Skip to content

Commit 4859b51

Browse files
committed
feat: Rename command and better error message
1 parent 7cf0e49 commit 4859b51

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ runtime, interpreter or package manager should make the setup easier in the end.
4040
#### With specific version
4141

4242
```bash
43-
nsd nodejs /path/ --version 12.15.0
43+
nsd download /path/ --version 12.15.0
4444
```
4545

4646
#### With specific version from file
4747

4848
```bash
49-
nsd nodejs /path/ --from-file ./node_version
49+
nsd download /path/ --from-file ./node_version
5050
```
5151

5252
#### No specific version, will try reading from CWD/.nvmrc
5353

5454
```bash
55-
nsd nodejs /path/
55+
nsd download /path/
5656
```
5757

5858
## How to build
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
)
1919

2020
var (
21-
version string
22-
fromFile string
23-
nodejsCommand = &cobra.Command{
24-
Use: "nodejs [path]",
21+
version string
22+
fromFile string
23+
downloadCommand = &cobra.Command{
24+
Use: "download [path]",
2525
Short: "Download nodejs to specific folder",
2626
Long: "",
2727
Args: func(cmd *cobra.Command, args []string) error {
@@ -84,7 +84,9 @@ func prepareFlags() (err error) {
8484
if version != "" && fromFile != "" {
8585
return errors.New("cannot figure out which version to install. Please only specify one of --version or --from-file")
8686
}
87+
versionSpecified := true
8788
if version == "" && fromFile == "" {
89+
versionSpecified = false
8890
fromFile = ".nvmrc"
8991
}
9092

@@ -96,6 +98,9 @@ func prepareFlags() (err error) {
9698

9799
content, err := ioutil.ReadFile(fromFile)
98100
if err != nil {
101+
if !versionSpecified {
102+
return errors.New("No version specified and could not find any version file in the current directory")
103+
}
99104
return err
100105
}
101106

@@ -106,8 +111,8 @@ func prepareFlags() (err error) {
106111
}
107112

108113
func init() {
109-
nodejsCommand.Flags().StringVarP(&version, "version", "v", "", "Which version to install")
110-
nodejsCommand.Flags().StringVarP(&fromFile, "from-file", "r", "", "Reads the version to be installed from a file. Either specify the filename or if empty it will try to read from .nvmrc file.")
111-
nodejsCommand.MarkFlagFilename("from-file")
112-
rootCmd.AddCommand(nodejsCommand)
114+
downloadCommand.Flags().StringVarP(&version, "version", "v", "", "Which version to install")
115+
downloadCommand.Flags().StringVarP(&fromFile, "from-file", "r", "", "Reads the version to be installed from a file. Either specify the filename or if empty it will try to read from .nvmrc file.")
116+
downloadCommand.MarkFlagFilename("from-file")
117+
rootCmd.AddCommand(downloadCommand)
113118
}

0 commit comments

Comments
 (0)