mirror of
https://github.com/89luca89/distrobox.git
synced 2026-08-17 16:34:42 -05:00
refactor(create): align flag Value with displayed default
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
+17
-3
@@ -53,18 +53,18 @@ Examples:
|
||||
&cli.StringFlag{
|
||||
Name: "image",
|
||||
Aliases: []string{"i"},
|
||||
Value: cfg.ContainerImage,
|
||||
Value: imageDefault,
|
||||
Usage: fmt.Sprintf("image to use for the container (default: %s)", imageDefault),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "name",
|
||||
Aliases: []string{"n"},
|
||||
Value: cfg.ContainerName,
|
||||
Value: nameDefault,
|
||||
Usage: fmt.Sprintf("name for the distrobox (default: %s)", nameDefault),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "hostname",
|
||||
Value: cfg.ContainerHostname,
|
||||
Value: hostnameDefault,
|
||||
Usage: fmt.Sprintf("hostname for the distrobox (default: %s)", hostnameDefault),
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
@@ -227,6 +227,20 @@ func createAction(ctx context.Context, cmd *cli.Command, cfg *config.Values) err
|
||||
NonInteractive: cmd.Bool("yes"),
|
||||
}
|
||||
|
||||
// Setting Value: to the resolved default (so --help is honest) means
|
||||
// cmd.String("name"/"hostname") returns that default even when the user
|
||||
// passed nothing on the CLI. Two shell branches rely on the option being
|
||||
// empty to fire — basename(image) in makeContainerName
|
||||
// (distrobox-create:495-497) and the `<name>.<host>` prefix under
|
||||
// --unshare-netns in makeContainerHostname (lines 503-505). When neither
|
||||
// the flag nor the env var was supplied, restore "" so they still fire.
|
||||
if !cmd.IsSet("name") && cfg.ContainerName == "" {
|
||||
opts.ContainerName = ""
|
||||
}
|
||||
if !cmd.IsSet("hostname") && cfg.ContainerHostname == "" {
|
||||
opts.ContainerHostname = ""
|
||||
}
|
||||
|
||||
// Positional container_name overrides --name, matching the shell
|
||||
// (distrobox-create:453-461) so `distrobox create --image alpine my-box`
|
||||
// names the box `my-box`.
|
||||
|
||||
Reference in New Issue
Block a user