Skip to content

Commit 675af1f

Browse files
committed
add --version flag
1 parent 6a20d96 commit 675af1f

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ gh combine owner/repo --ignore-labels wip,dependencies
180180
gh combine owner/repo --update-branch
181181
```
182182

183+
### Display Version Information
184+
185+
```bash
186+
gh combine --version
187+
```
188+
183189
### Disable Stats Output
184190

185191
```bash

internal/cmd/root.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ func NewRootCmd() *cobra.Command {
125125
gh combine owner/repo --output table # Output stats in table format (default)
126126
gh combine owner/repo --combine-branch-name combined-prs # Use a different name for the combined PR branch
127127
gh combine owner/repo --working-branch-suffix -working # Use a different suffix for the working branch
128-
gh combine owner/repo --update-branch # Update the branch of the combined PR`,
128+
gh combine owner/repo --update-branch # Update the branch of the combined PR
129+
gh combine --version # Display version information`,
129130
RunE: runCombine,
130131
}
131132

@@ -158,11 +159,8 @@ func NewRootCmd() *cobra.Command {
158159
rootCmd.Flags().StringVar(&outputFormat, "output", "table", "Output format: table, plain, or json")
159160
rootCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Simulate the actions without making any changes")
160161

161-
// Add deprecated flags for backward compatibility
162-
// rootCmd.Flags().IntVar(&minimum, "min-combine", 2, "Minimum number of PRs to combine (deprecated, use --minimum)")
163-
164-
// Mark deprecated flags
165-
// rootCmd.Flags().MarkDeprecated("min-combine", "use --minimum instead")
162+
// Add version flag
163+
rootCmd.Flags().BoolP("version", "v", false, "Display version information")
166164

167165
return rootCmd
168166
}
@@ -178,6 +176,15 @@ func runCombine(cmd *cobra.Command, args []string) error {
178176
ctx, cancel := SetupSignalContext()
179177
defer cancel()
180178

179+
// Check for version flag before executing the command
180+
if cmd.Flags().Lookup("version") != nil {
181+
versionFlagValue, err := cmd.Flags().GetBool("version")
182+
if err == nil && versionFlagValue {
183+
fmt.Println(version.String())
184+
return nil
185+
}
186+
}
187+
181188
Logger.Debug("starting gh-combine", "version", version.String())
182189

183190
if dependabot && branchPrefix == "" {
@@ -425,7 +432,7 @@ func buildCommandString(args []string) string {
425432
cmd = append(cmd, args...)
426433

427434
// Only add branch-prefix if it's not due to the dependabot flag
428-
if branchPrefix != "" && !(dependabot && branchPrefix == "dependabot/") {
435+
if branchPrefix != "" && (!dependabot || branchPrefix != "dependabot/") {
429436
cmd = append(cmd, "--branch-prefix", branchPrefix)
430437
}
431438
if branchSuffix != "" {

0 commit comments

Comments
 (0)