Skip to content

Commit

Permalink
UPDATE rm confirmation, license
Browse files Browse the repository at this point in the history
  • Loading branch information
RecuencoJones committed Aug 16, 2018
1 parent e9150b7 commit 4331da7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.1

- Added remove confirmation
- Added LICENSE

# 0.1.0

- Initial release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions cmd/npmrc/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"
"io/ioutil"
"log"
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 12 additions & 4 deletions cmd/npmrc/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func RemoveHandler(args []string, options RemoveOptions) {
os.Exit(1)
}

if !options.force {
// TODO prompt
}

profile := args[0]

if !ProfileExists(profile) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/npmrc/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 4331da7

Please sign in to comment.