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

Commit 330795e

Browse files
author
Matthieu Nottale
committed
cmd: Factor optional appname extraction from args
1 parent 080c986 commit 330795e

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
@@ -28,11 +28,7 @@ var helmCmd = &cobra.Command{
2828
}
2929
d[kv[0]] = kv[1]
3030
}
31-
app := ""
32-
if len(args) > 0 {
33-
app = args[0]
34-
}
35-
return renderer.Helm(app, helmComposeFiles, helmSettingsFile, d)
31+
return renderer.Helm(firstOrEmpty(args), helmComposeFiles, helmSettingsFile, d)
3632
},
3733
}
3834

cmd/inspect.go

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

cmd/load.go

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

cmd/pack.go

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

cmd/push.go

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

cmd/render.go

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

cmd/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ var rootCmd = &cobra.Command{
1414
Long: "",
1515
}
1616

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

cmd/save.go

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

cmd/unpack.go

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

0 commit comments

Comments
 (0)