File tree Expand file tree Collapse file tree 8 files changed +99
-10
lines changed Expand file tree Collapse file tree 8 files changed +99
-10
lines changed Original file line number Diff line number Diff line change @@ -9,16 +9,17 @@ install:
9
9
10
10
script :
11
11
- go install ./...
12
- - gox -output="bin/{{.Dir }}_{{.OS}}_ {{.Arch }}" ./...
12
+ - gox -output="bin/{{.OS }}_{{.Arch}}/ {{.Dir }}" ./...
13
13
14
14
before_deploy :
15
15
- export VERSION=`npmrc version`
16
+ - for i in bin/*; do tar -zvcf "$i.tar.gz" "$i"; done
16
17
17
18
deploy :
18
19
provider : releases
19
20
api_key : $GITHUB_TOKEN
20
21
file_glob : true
21
- file : bin/**/*
22
+ file : bin/*.tar.gz
22
23
skip_cleanup : true
23
24
name : npmrc $VERSION
24
25
on :
Original file line number Diff line number Diff line change
1
+ ## 0.1.2
2
+
3
+ - Added profile name validation
4
+ - Added copy to current directory
5
+ - Updated help and readme
6
+ - Updated .travis.yml to compress files before uploading
7
+
1
8
## 0.1.1
2
9
3
10
- Added remove confirmation
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ go install ./...
15
15
16
16
## Installation from releases
17
17
18
- - Download the binary for your distribution
19
- - Rename it to ` npmrc `
18
+ - Download the file for your distribution
19
+ - Extract it to get ` npmrc `
20
20
- Make it available in your path
21
21
22
22
Happy ` .npmrc ` switching!
@@ -43,5 +43,13 @@ version Display version
43
43
| Env variable | Default value | Description |
44
44
| --- | --- | --- |
45
45
| NPMRC_DIR | ` ~ ` | Directory where profiles will be stored |
46
- | EDITOR | ` vim ` | Editor to use for creating/editing profiles |
46
+ | EDITOR | ` vi ` | Editor to use for creating/editing profiles |
47
47
| VIEWER | ` cat ` | Viewer to use for viewing profiles |
48
+
49
+ ## Profile name rules
50
+
51
+ - Profile name must not start with ` . `
52
+ - Profile name must not contain spaces
53
+ - Profile name must be of at least 1 character length
54
+
55
+ [ Check regex at regexr.com] ( https://regexr.com/3u5rg )
Original file line number Diff line number Diff line change @@ -43,15 +43,29 @@ func CopyHandler(args []string, options CopyOptions) {
43
43
44
44
// Copy source profile to destination profile
45
45
func Copy (srcProfile , destProfile string ) error {
46
+ var dest string
47
+
46
48
// check profile is valid
47
49
if ! ProfileExists (srcProfile ) {
48
50
fmt .Println ("Error: Profile \" " + srcProfile + "\" does not exist" )
49
51
os .Exit (1 )
50
52
}
51
53
54
+ if destProfile == "." {
55
+ dir , err := os .Getwd ()
56
+ if err != nil {
57
+ log .Fatal (err )
58
+ os .Exit (1 )
59
+ }
60
+
61
+ dest = path .Join (dir , NpmrcFile )
62
+ } else {
63
+ ValidateProfile (destProfile )
64
+ dest = path .Join (Dir , NpmrcFile + "." + destProfile )
65
+ }
66
+
52
67
// copy from $npmrc_dir/.npmrc.$srcProfile to $npmrc_dir/.npmrc.$destProfile
53
68
source := path .Join (Dir , NpmrcFile + "." + srcProfile )
54
- dest := path .Join (Dir , NpmrcFile + "." + destProfile )
55
69
56
70
return CP (source , dest )
57
71
}
@@ -66,5 +80,9 @@ Alias: cp
66
80
Available flags:
67
81
68
82
verbose Display additional output
69
- h Display this message` )
83
+ h Display this message
84
+
85
+ Details:
86
+
87
+ If <destProfile> is ".", the selected profile is copied to current working directory.` )
70
88
}
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ type EditOptions struct {
18
18
func EditHandler (args []string , options EditOptions ) {
19
19
profile := args [0 ]
20
20
21
+ ValidateProfile (profile )
22
+
21
23
if options .verbose {
22
24
if ! ProfileExists (profile ) {
23
25
fmt .Println ("Creating profile \" " + profile + "\" " )
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ func main() {
136
136
// Help display usage of npmrc command
137
137
func Help () {
138
138
fmt .Println (`
139
- Usage: npmrc <command> [flags]
139
+ Usage: npmrc <command>
140
140
141
141
Available commands:
142
142
@@ -147,5 +147,13 @@ edit, ed Create or update profiles
147
147
copy, cp Copy profiles
148
148
remove, rm Remove a profile
149
149
help, h Display this message
150
- version Display version` )
150
+ version Display version
151
+
152
+ Profile names:
153
+
154
+ A profile names must comply with the following:
155
+
156
+ - Must not start with "."
157
+ - Must not contain spaces
158
+ - Must be of at least 1 character length` )
151
159
}
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "errors"
5
+ "fmt"
6
+ "os"
7
+ "strings"
8
+ )
9
+
10
+ // IsProfileValid checks if a given profile name complies with the naming rules
11
+ func IsProfileValid (profile string ) (bool , []error ) {
12
+ var errs []error
13
+
14
+ if strings .HasPrefix (profile , "." ) {
15
+ err := errors .New ("Profile name cannot start with \" .\" " )
16
+
17
+ errs = append (errs , err )
18
+ }
19
+
20
+ if strings .Contains (profile , " " ) {
21
+ err := errors .New ("Profile name cannot contain spaces" )
22
+
23
+ errs = append (errs , err )
24
+ }
25
+
26
+ if len (profile ) < 1 {
27
+ err := errors .New ("Profile name must be at least one character long" )
28
+
29
+ errs = append (errs , err )
30
+ }
31
+
32
+ return len (errs ) == 0 , errs
33
+ }
34
+
35
+ // ValidateProfile aborts execution if profile is non compliant
36
+ func ValidateProfile (profile string ) {
37
+ isValid , errors := IsProfileValid (profile )
38
+
39
+ if ! isValid {
40
+ for _ , err := range errors {
41
+ fmt .Println (err )
42
+ }
43
+ os .Exit (1 )
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import homedir "github.com/mitchellh/go-homedir"
4
4
5
5
// NpmrcFile base name
6
6
const (
7
- Version = "0.1.1 "
7
+ Version = "0.1.2 "
8
8
NpmrcFile = ".npmrc"
9
9
)
10
10
You can’t perform that action at this time.
0 commit comments