Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 69d4ccd

Browse files
authored
Merge pull request #55 from mnottale/cmd-factor-appname-extraction
cmd: Factor optional appname extraction from args
2 parents a510528 + 330795e commit 69d4ccd

File tree

9 files changed

+15
-40
lines changed

9 files changed

+15
-40
lines changed

cmd/helm.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ var helmCmd = &cobra.Command{
2929
}
3030
d[kv[0]] = kv[1]
3131
}
32-
app := ""
33-
if len(args) > 0 {
34-
app = args[0]
35-
}
36-
return renderer.Helm(app, helmComposeFiles, helmSettingsFile, d)
32+
return renderer.Helm(firstOrEmpty(args), helmComposeFiles, helmSettingsFile, d)
3733
},
3834
}
3935

cmd/inspect.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ var inspectCmd = &cobra.Command{
1212
Short: "Retrieve metadata for a given app package",
1313
Args: cli.RequiresMaxArgs(1),
1414
RunE: func(cmd *cobra.Command, args []string) error {
15-
app := ""
16-
if len(args) > 0 {
17-
app = args[0]
18-
}
19-
return packager.Inspect(app)
15+
return packager.Inspect(firstOrEmpty(args))
2016
},
2117
}
2218

cmd/load.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ var loadCmd = &cobra.Command{
1212
Short: "Load an app from docker",
1313
Args: cli.RequiresMaxArgs(1),
1414
RunE: func(cmd *cobra.Command, args []string) error {
15-
app := ""
16-
if len(args) > 0 {
17-
app = args[0]
18-
}
19-
return packager.Load(app)
15+
return packager.Load(firstOrEmpty(args))
2016
},
2117
}
2218

cmd/pack.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ var packCmd = &cobra.Command{
1212
Short: "Pack this app as a single file",
1313
Args: cli.RequiresMaxArgs(1),
1414
RunE: func(cmd *cobra.Command, args []string) error {
15-
app := ""
16-
if len(args) > 0 {
17-
app = args[0]
18-
}
19-
return packager.Pack(app, packOutputFile)
15+
return packager.Pack(firstOrEmpty(args), packOutputFile)
2016
},
2117
}
2218

cmd/push.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ var pushCmd = &cobra.Command{
1515
if pushTag == "" {
1616
pushTag = "latest"
1717
}
18-
app := ""
19-
if len(args) > 0 {
20-
app = args[0]
21-
}
22-
return packager.Push(app, pushPrefix, pushTag)
18+
return packager.Push(firstOrEmpty(args), pushPrefix, pushTag)
2319
},
2420
}
2521

cmd/render.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ Override is provided in different ways:
3737
}
3838
d[kv[0]] = kv[1]
3939
}
40-
app := ""
41-
if len(args) > 0 {
42-
app = args[0]
43-
}
44-
rendered, err := renderer.Render(app, renderComposeFiles, renderSettingsFile, d)
40+
rendered, err := renderer.Render(firstOrEmpty(args), renderComposeFiles, renderSettingsFile, d)
4541
if err != nil {
4642
return err
4743
}

cmd/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ var rootCmd = &cobra.Command{
1212
SilenceUsage: true,
1313
}
1414

15+
func firstOrEmpty(list []string) string {
16+
if len(list) != 0 {
17+
return list[0]
18+
}
19+
return ""
20+
}
21+
1522
// Execute adds all child commands to the root command and sets flags appropriately.
1623
// This is called by main.main(). It only needs to happen once to the rootCmd.
1724
func Execute() {

cmd/save.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ var saveCmd = &cobra.Command{
1515
if saveTag == "" {
1616
saveTag = "latest"
1717
}
18-
app := ""
19-
if len(args) > 0 {
20-
app = args[0]
21-
}
22-
return packager.Save(app, savePrefix, saveTag)
18+
return packager.Save(firstOrEmpty(args), savePrefix, saveTag)
2319
},
2420
}
2521

cmd/unpack.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ var unpackCmd = &cobra.Command{
1212
Short: "Unpack the app to expose the content",
1313
Args: cli.RequiresMaxArgs(1),
1414
RunE: func(cmd *cobra.Command, args []string) error {
15-
app := ""
16-
if len(args) > 0 {
17-
app = args[0]
18-
}
19-
return packager.Unpack(app, unpackOutputDir)
15+
return packager.Unpack(firstOrEmpty(args), unpackOutputDir)
2016
},
2117
}
2218

0 commit comments

Comments
 (0)