@@ -26,43 +26,21 @@ export interface ParsedArgs {
26
26
*/
27
27
export async function parseArgs ( ) : Promise < ParsedArgs > {
28
28
try {
29
- const cli = cac ( 'bumpp' )
30
-
31
- cli
32
- . version ( version )
33
- . usage ( '[...files]' )
34
- . option ( '--preid <preid>' , 'ID for prerelease' )
35
- . option ( '--all' , `Include all files (default: ${ bumpConfigDefaults . all } )` )
36
- . option ( '-c, --commit [msg]' , `Commit message (default: ${ bumpConfigDefaults . commit } )` )
37
- . option ( '--no-commit' , 'Skip commit' )
38
- . option ( '-t, --tag [tag]' , `Tag name (default: ${ bumpConfigDefaults . tag } )` )
39
- . option ( '--no-tag' , 'Skip tag' )
40
- . option ( '-p, --push' , `Push to remote (default: ${ bumpConfigDefaults . push } )` )
41
- . option ( '-y, --yes' , `Skip confirmation (default: ${ ! bumpConfigDefaults . confirm } )` )
42
- . option ( '-r, --recursive' , `Bump package.json files recursively (default: ${ bumpConfigDefaults . recursive } )` )
43
- . option ( '--no-verify' , 'Skip git verification' )
44
- . option ( '--ignore-scripts' , `Ignore scripts (default: ${ bumpConfigDefaults . ignoreScripts } )` )
45
- . option ( '-q, --quiet' , 'Quiet mode' )
46
- . option ( '-v, --version <version>' , 'Target version' )
47
- . option ( '-x, --execute <command>' , 'Commands to execute after version bumps' )
48
- . help ( )
49
-
50
- const result = cli . parse ( )
51
- const args = result . options
29
+ const { args, resultArgs } = loadCliArgs ( )
52
30
53
31
const parsedArgs : ParsedArgs = {
54
32
help : args . help as boolean ,
55
33
version : args . version as boolean ,
56
34
quiet : args . quiet as boolean ,
57
35
options : await loadBumpConfig ( {
58
36
preid : args . preid ,
59
- commit : ! args . noCommit && args . commit ,
60
- tag : ! args . noTag && args . tag ,
37
+ commit : args . commit ,
38
+ tag : args . tag ,
61
39
push : args . push ,
62
40
all : args . all ,
63
41
confirm : ! args . yes ,
64
42
noVerify : ! args . verify ,
65
- files : [ ...( args [ '--' ] || [ ] ) , ...result . args ] ,
43
+ files : [ ...( args [ '--' ] || [ ] ) , ...resultArgs ] ,
66
44
ignoreScripts : args . ignoreScripts ,
67
45
execute : args . execute ,
68
46
recursive : ! ! args . recursive ,
@@ -116,6 +94,47 @@ export async function parseArgs(): Promise<ParsedArgs> {
116
94
}
117
95
}
118
96
97
+ export function loadCliArgs ( argv = process . argv ) {
98
+ const cli = cac ( 'bumpp' )
99
+
100
+ cli
101
+ . version ( version )
102
+ . usage ( '[...files]' )
103
+ . option ( '--preid <preid>' , 'ID for prerelease' )
104
+ . option ( '--all' , `Include all files (default: ${ bumpConfigDefaults . all } )` )
105
+ . option ( '-c, --commit [msg]' , 'Commit message' , { default : true } )
106
+ . option ( '--no-commit' , 'Skip commit' , { default : false } )
107
+ . option ( '-t, --tag [tag]' , 'Tag name' , { default : true } )
108
+ . option ( '--no-tag' , 'Skip tag' , { default : false } )
109
+ . option ( '-p, --push' , `Push to remote (default: ${ bumpConfigDefaults . push } )` )
110
+ . option ( '-y, --yes' , `Skip confirmation (default: ${ ! bumpConfigDefaults . confirm } )` )
111
+ . option ( '-r, --recursive' , `Bump package.json files recursively (default: ${ bumpConfigDefaults . recursive } )` )
112
+ . option ( '--no-verify' , 'Skip git verification' )
113
+ . option ( '--ignore-scripts' , `Ignore scripts (default: ${ bumpConfigDefaults . ignoreScripts } )` )
114
+ . option ( '-q, --quiet' , 'Quiet mode' )
115
+ . option ( '-v, --version <version>' , 'Target version' )
116
+ . option ( '-x, --execute <command>' , 'Commands to execute after version bumps' )
117
+ . help ( )
118
+
119
+ const result = cli . parse ( argv )
120
+ const rawArgs = cli . rawArgs
121
+ const args = result . options
122
+
123
+ const hasCommitFlag = rawArgs . some ( arg => [ '-c' , '--commit' , '--no-commit' ] . includes ( arg ) )
124
+ const hasTagFlag = rawArgs . some ( arg => [ '-t' , '--tag' , '--no-tag' ] . includes ( arg ) )
125
+
126
+ const { tag, commit, ...rest } = args
127
+
128
+ return {
129
+ args : {
130
+ ...rest ,
131
+ commit : hasCommitFlag ? commit : undefined ,
132
+ tag : hasTagFlag ? tag : undefined ,
133
+ } as { [ k : string ] : any } ,
134
+ resultArgs : result . args ,
135
+ }
136
+ }
137
+
119
138
function errorHandler ( error : Error ) : never {
120
139
console . error ( error . message )
121
140
return process . exit ( ExitCode . InvalidArgument )
0 commit comments