Skip to content

Commit 4331da7

Browse files
committed
UPDATE rm confirmation, license
1 parent e9150b7 commit 4331da7

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.1
2+
3+
- Added remove confirmation
4+
- Added LICENSE
5+
16
# 0.1.0
27

38
- Initial release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-present David Recuenco
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

cmd/npmrc/common.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"io"
56
"io/ioutil"
67
"log"
@@ -31,6 +32,24 @@ func GetProfiles() []string {
3132
return profileNames
3233
}
3334

35+
// AskConfirmation via prompt with given message
36+
func AskConfirmation(message string) bool {
37+
var answer string
38+
39+
fmt.Printf("%s (y/N): ", message)
40+
41+
_, err := fmt.Scanln(&answer)
42+
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
answer = strings.TrimSpace(answer)
48+
answer = strings.ToLower(answer)
49+
50+
return answer == "y" || answer == "yes"
51+
}
52+
3453
// GetEnv attempts to retrieve an env variable or returns given default value
3554
func GetEnv(name, defaultValue string) string {
3655
if value, ok := os.LookupEnv(name); ok {

cmd/npmrc/remove.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ func RemoveHandler(args []string, options RemoveOptions) {
2727
os.Exit(1)
2828
}
2929

30-
if !options.force {
31-
// TODO prompt
32-
}
33-
3430
profile := args[0]
3531

3632
if !ProfileExists(profile) {
@@ -41,6 +37,18 @@ func RemoveHandler(args []string, options RemoveOptions) {
4137
os.Exit(0)
4238
}
4339

40+
if !options.force {
41+
confirm := AskConfirmation("Are you sure you want to remove profile \"" + profile + "\"?")
42+
43+
if !confirm {
44+
if options.verbose {
45+
fmt.Println("Refuted to remove \"" + profile + "\". Nothing to do here.")
46+
}
47+
48+
os.Exit(0)
49+
}
50+
}
51+
4452
err := Remove(profile)
4553

4654
if err != nil {

cmd/npmrc/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import homedir "github.com/mitchellh/go-homedir"
44

55
// NpmrcFile base name
66
const (
7-
Version = "0.1.0"
7+
Version = "0.1.1"
88
NpmrcFile = ".npmrc"
99
)
1010

0 commit comments

Comments
 (0)