Skip to content

Commit 49df63e

Browse files
committed
reuse shared flags
1 parent b58ddc7 commit 49df63e

File tree

3 files changed

+41
-56
lines changed

3 files changed

+41
-56
lines changed

cmd/git-back/main.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/signal"
77
"syscall"
88

9+
"github.com/amberpixels/git-undo/cmd/shared"
910
"github.com/amberpixels/git-undo/internal/app"
1011
"github.com/urfave/cli/v3"
1112
)
@@ -29,34 +30,7 @@ func main() {
2930
cmd := &cli.Command{
3031
Name: appNameGitBack,
3132
Usage: "Navigate back through git checkout/switch operations",
32-
Flags: []cli.Flag{
33-
&cli.BoolFlag{
34-
Name: "help",
35-
Aliases: []string{"h"},
36-
Usage: "Show help",
37-
},
38-
&cli.BoolFlag{
39-
Name: "verbose",
40-
Aliases: []string{"v"},
41-
Usage: "Enable verbose output",
42-
},
43-
&cli.BoolFlag{
44-
Name: "dry-run",
45-
Usage: "Show what would be executed without running commands",
46-
},
47-
&cli.BoolFlag{
48-
Name: "version",
49-
Usage: "Print the version",
50-
},
51-
&cli.StringFlag{
52-
Name: "hook",
53-
Usage: "Hook command for shell integration (internal use)",
54-
},
55-
&cli.BoolFlag{
56-
Name: "log",
57-
Usage: "Display the git-undo command log",
58-
},
59-
},
33+
Flags: shared.CommonFlags(),
6034
Action: func(ctx context.Context, c *cli.Command) error {
6135
a := app.NewAppGitBack(version, versionSource)
6236

cmd/git-undo/main.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/signal"
77
"syscall"
88

9+
"github.com/amberpixels/git-undo/cmd/shared"
910
"github.com/amberpixels/git-undo/internal/app"
1011
"github.com/urfave/cli/v3"
1112
)
@@ -31,34 +32,7 @@ func main() {
3132
Usage: "Universal \"Ctrl + Z\" for Git commands",
3233
DisableSliceFlagSeparator: true,
3334
HideHelp: true,
34-
Flags: []cli.Flag{
35-
&cli.BoolFlag{
36-
Name: "help",
37-
Aliases: []string{"h"},
38-
Usage: "Show help",
39-
},
40-
&cli.BoolFlag{
41-
Name: "verbose",
42-
Aliases: []string{"v"},
43-
Usage: "Enable verbose output",
44-
},
45-
&cli.BoolFlag{
46-
Name: "dry-run",
47-
Usage: "Show what would be executed without running commands",
48-
},
49-
&cli.BoolFlag{
50-
Name: "version",
51-
Usage: "Print the version",
52-
},
53-
&cli.StringFlag{
54-
Name: "hook",
55-
Usage: "Hook command for shell integration (internal use)",
56-
},
57-
&cli.BoolFlag{
58-
Name: "log",
59-
Usage: "Display the git-undo command log",
60-
},
61-
},
35+
Flags: shared.CommonFlags(),
6236
Action: func(ctx context.Context, c *cli.Command) error {
6337
application := app.NewAppGitUndo(version, versionSource)
6438
if c.Bool("version") {

cmd/shared/flags.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package shared
2+
3+
import (
4+
"github.com/urfave/cli/v3"
5+
)
6+
7+
// CommonFlags returns the standard set of CLI flags used by both git-undo and git-back commands.
8+
func CommonFlags() []cli.Flag {
9+
return []cli.Flag{
10+
&cli.BoolFlag{
11+
Name: "help",
12+
Aliases: []string{"h"},
13+
Usage: "Show help",
14+
},
15+
&cli.BoolFlag{
16+
Name: "verbose",
17+
Aliases: []string{"v"},
18+
Usage: "Enable verbose output",
19+
},
20+
&cli.BoolFlag{
21+
Name: "dry-run",
22+
Usage: "Show what would be executed without running commands",
23+
},
24+
&cli.BoolFlag{
25+
Name: "version",
26+
Usage: "Print the version",
27+
},
28+
&cli.StringFlag{
29+
Name: "hook",
30+
Usage: "Hook command for shell integration (internal use)",
31+
},
32+
&cli.BoolFlag{
33+
Name: "log",
34+
Usage: "Display the git-undo command log",
35+
},
36+
}
37+
}

0 commit comments

Comments
 (0)