Skip to content

Commit 02b6652

Browse files
stevengregoryclaude
andcommitted
feat: simplify deploy syntax with positional env argument
Replace --env flag with positional argument for cleaner usage: musing deploy news prod (was: musing deploy news --env prod) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f3c6e93 commit 02b6652

2 files changed

Lines changed: 41 additions & 31 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ Deploy MongoDB collections to dev or production.
111111

112112
```bash
113113
musing deploy # All collections to dev
114-
musing deploy news # Specific collection to dev
115-
musing deploy --env prod # All to prod (with confirmation)
116-
musing deploy news -e prod # Specific collection to prod
114+
musing deploy news # Deploy news to dev
115+
musing deploy news prod # Deploy news to prod
117116
```
118117

119118
**How it works:**
@@ -126,7 +125,8 @@ musing deploy news -e prod # Specific collection to prod
126125
**Production safety:**
127126

128127
- Interactive confirmation required
129-
- Verifies SSH tunnel connectivity
128+
- Auto-opens SSH tunnel if not already running
129+
- Auto-closes tunnel after deployment completes
130130
- Clear warnings about data overwrite
131131

132132
### version

cmd/deploy.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,59 @@ var (
2525
)
2626

2727
var deployCmd = &cobra.Command{
28-
Use: "deploy [collection]",
28+
Use: "deploy [collection] [env]",
2929
Short: "Deploy MongoDB data collections",
30-
Long: `Deploy MongoDB data collections to development or production environment.`,
31-
Args: cobra.MaximumNArgs(1),
30+
Long: `Deploy MongoDB data collections to development or production environment.
31+
32+
Examples:
33+
musing deploy # All collections to dev
34+
musing deploy news # Deploy news to dev
35+
musing deploy news prod # Deploy news to prod`,
36+
Args: cobra.MaximumNArgs(2),
3237
RunE: func(cmd *cobra.Command, args []string) error {
3338
collection := "all"
39+
env := "dev"
3440
if len(args) > 0 {
3541
collection = args[0]
3642
}
43+
if len(args) > 1 {
44+
env = args[1]
45+
}
46+
47+
if env != "dev" && env != "prod" {
48+
return fmt.Errorf("invalid environment: %s (use 'dev' or 'prod')", env)
49+
}
3750

38-
env, _ := cmd.Flags().GetString("env")
3951
return deployData(collection, env)
4052
},
4153
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
42-
// Dynamic completion for collection names
43-
config.MustFindProjectRoot()
44-
cfg := config.GetConfig()
45-
if cfg == nil {
46-
return nil, cobra.ShellCompDirectiveNoFileComp
47-
}
54+
if len(args) == 0 {
55+
// First arg: collection names
56+
config.MustFindProjectRoot()
57+
cfg := config.GetConfig()
58+
if cfg == nil {
59+
return nil, cobra.ShellCompDirectiveNoFileComp
60+
}
4861

49-
collections, err := mongo.DiscoverCollections(cfg.Database.DataDir)
50-
if err != nil {
51-
return nil, cobra.ShellCompDirectiveNoFileComp
52-
}
62+
collections, err := mongo.DiscoverCollections(cfg.Database.DataDir)
63+
if err != nil {
64+
return nil, cobra.ShellCompDirectiveNoFileComp
65+
}
5366

54-
var names []string
55-
for name := range collections {
56-
names = append(names, name)
67+
var names []string
68+
for name := range collections {
69+
names = append(names, name)
70+
}
71+
return names, cobra.ShellCompDirectiveNoFileComp
72+
}
73+
if len(args) == 1 {
74+
// Second arg: environment
75+
return []string{"dev", "prod"}, cobra.ShellCompDirectiveNoFileComp
5776
}
58-
return names, cobra.ShellCompDirectiveNoFileComp
77+
return nil, cobra.ShellCompDirectiveNoFileComp
5978
},
6079
}
6180

62-
func init() {
63-
deployCmd.Flags().StringP("env", "e", "dev", "Environment: dev or prod")
64-
65-
// Add completion for env flag
66-
deployCmd.RegisterFlagCompletionFunc("env", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
67-
return []string{"dev", "prod"}, cobra.ShellCompDirectiveNoFileComp
68-
})
69-
}
70-
7181
func deployData(collection, env string) error {
7282
// Find and load project configuration
7383
config.MustFindProjectRoot()

0 commit comments

Comments
 (0)