From 4331da719fc5f7fbb40aa429c20c07a14a72f5eb Mon Sep 17 00:00:00 2001 From: David Recuenco Date: Thu, 16 Aug 2018 14:59:02 +0200 Subject: [PATCH] UPDATE rm confirmation, license --- CHANGELOG.md | 5 +++++ LICENSE | 21 +++++++++++++++++++++ cmd/npmrc/common.go | 19 +++++++++++++++++++ cmd/npmrc/remove.go | 16 ++++++++++++---- cmd/npmrc/variables.go | 2 +- 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 LICENSE diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fafbcd..864fac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.1 + +- Added remove confirmation +- Added LICENSE + # 0.1.0 - Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..17df3ab --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018-present David Recuenco + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cmd/npmrc/common.go b/cmd/npmrc/common.go index cee4216..221fdad 100644 --- a/cmd/npmrc/common.go +++ b/cmd/npmrc/common.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "io" "io/ioutil" "log" @@ -31,6 +32,24 @@ func GetProfiles() []string { return profileNames } +// AskConfirmation via prompt with given message +func AskConfirmation(message string) bool { + var answer string + + fmt.Printf("%s (y/N): ", message) + + _, err := fmt.Scanln(&answer) + + if err != nil { + panic(err) + } + + answer = strings.TrimSpace(answer) + answer = strings.ToLower(answer) + + return answer == "y" || answer == "yes" +} + // GetEnv attempts to retrieve an env variable or returns given default value func GetEnv(name, defaultValue string) string { if value, ok := os.LookupEnv(name); ok { diff --git a/cmd/npmrc/remove.go b/cmd/npmrc/remove.go index 3f7ec00..1568970 100644 --- a/cmd/npmrc/remove.go +++ b/cmd/npmrc/remove.go @@ -27,10 +27,6 @@ func RemoveHandler(args []string, options RemoveOptions) { os.Exit(1) } - if !options.force { - // TODO prompt - } - profile := args[0] if !ProfileExists(profile) { @@ -41,6 +37,18 @@ func RemoveHandler(args []string, options RemoveOptions) { os.Exit(0) } + if !options.force { + confirm := AskConfirmation("Are you sure you want to remove profile \"" + profile + "\"?") + + if !confirm { + if options.verbose { + fmt.Println("Refuted to remove \"" + profile + "\". Nothing to do here.") + } + + os.Exit(0) + } + } + err := Remove(profile) if err != nil { diff --git a/cmd/npmrc/variables.go b/cmd/npmrc/variables.go index 0ef36c0..2ea3aa8 100644 --- a/cmd/npmrc/variables.go +++ b/cmd/npmrc/variables.go @@ -4,7 +4,7 @@ import homedir "github.com/mitchellh/go-homedir" // NpmrcFile base name const ( - Version = "0.1.0" + Version = "0.1.1" NpmrcFile = ".npmrc" )