refactor(create): align flag Value with displayed default

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
Luca Di Maio
2026-06-25 09:07:26 +02:00
parent bdc2576f2c
commit c574800e72
+17 -3
View File
@@ -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`.