Skip to content

Commit 4a41421

Browse files
authored
Merge pull request #64 from huantianad/main
Add -v/--version, -h/--help description edit
2 parents b6cd21c + f75ae36 commit 4a41421

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/pax.nim

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import therapist
22
import cmd/add, cmd/expo, cmd/impo, cmd/init, cmd/list, cmd/pin, cmd/remove, cmd/update, cmd/upgrade, cmd/version
33
import term/color, term/prompt
4+
import util/paxVersion
45

56
let commonArgs = (
67
strategy: newStringArg(@["-s", "--strategy"],
@@ -13,6 +14,14 @@ let commonArgs = (
1314
),
1415
noColor: newCountArg(@["--no-color"],
1516
help = "disable colored output"
17+
),
18+
# Version should only work with no subcommands
19+
version: newMessageArg(@["-v", "--version"],
20+
currentPaxVersion,
21+
help = "show version information"
22+
),
23+
help: newHelpArg(@["-h", "--help"],
24+
help = "show help message"
1625
)
1726
)
1827

@@ -28,7 +37,7 @@ let initCmd = (
2837
),
2938
yes: commonArgs.yes,
3039
noColor: commonArgs.noColor,
31-
help: newHelpArg()
40+
help: commonArgs.help
3241
)
3342

3443
let listCmd = (
@@ -40,7 +49,7 @@ let listCmd = (
4049
),
4150
yes: commonArgs.yes,
4251
noColor: commonArgs.noColor,
43-
help: newHelpArg()
52+
help: commonArgs.help
4453
)
4554

4655
let addCmd = (
@@ -54,7 +63,7 @@ let addCmd = (
5463
strategy: commonArgs.strategy,
5564
yes: commonArgs.yes,
5665
noColor: commonArgs.noColor,
57-
help: newHelpArg()
66+
help: commonArgs.help
5867
)
5968

6069
let removeCmd = (
@@ -65,7 +74,7 @@ let removeCmd = (
6574
strategy: commonArgs.strategy,
6675
yes: commonArgs.yes,
6776
noColor: commonArgs.noColor,
68-
help: newHelpArg()
77+
help: commonArgs.help
6978
)
7079

7180
let pinCmd = (
@@ -75,7 +84,7 @@ let pinCmd = (
7584
),
7685
yes: commonArgs.yes,
7786
noColor: commonArgs.noColor,
78-
help: newHelpArg()
87+
help: commonArgs.help
7988
)
8089

8190
let updateCmd = (
@@ -86,14 +95,14 @@ let updateCmd = (
8695
strategy: commonArgs.strategy,
8796
yes: commonArgs.yes,
8897
noColor: commonArgs.noColor,
89-
help: newHelpArg()
98+
help: commonArgs.help
9099
)
91100

92101
let upgradeCmd = (
93102
strategy: commonArgs.strategy,
94103
yes: commonArgs.yes,
95104
noColor: commonArgs.noColor,
96-
help: newHelpArg()
105+
help: commonArgs.help
97106
)
98107

99108
let versionCmd = (
@@ -109,7 +118,7 @@ let versionCmd = (
109118
),
110119
yes: commonArgs.yes,
111120
noColor: commonArgs.noColor,
112-
help: newHelpArg()
121+
help: commonArgs.help
113122
)
114123

115124
let importCmd = (
@@ -124,7 +133,7 @@ let importCmd = (
124133
),
125134
yes: commonArgs.yes,
126135
noColor: commonArgs.noColor,
127-
help: newHelpArg()
136+
help: commonArgs.help
128137
)
129138

130139
let exportCmd = (
@@ -135,7 +144,7 @@ let exportCmd = (
135144
),
136145
yes: commonArgs.yes,
137146
noColor: commonArgs.noColor,
138-
help: newHelpArg()
147+
help: commonArgs.help
139148
)
140149

141150
let spec = (
@@ -181,7 +190,8 @@ let spec = (
181190
),
182191
yes: commonArgs.yes,
183192
noColor: commonArgs.noColor,
184-
help: newHelpArg()
193+
paxVersion: commonArgs.version,
194+
help: commonArgs.help
185195
)
186196

187197
spec.parseOrHelp()

src/util/paxVersion.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Helper file for retrieving pax version from latest tag
2+
3+
import strutils
4+
5+
const currentPaxVersion*: string = staticExec("git describe --tags HEAD").split("-")[0]

0 commit comments

Comments
 (0)