diff --git a/cmd/chisel/cmd_cut.go b/cmd/chisel/cmd_cut.go index 7fee56e8..f8992270 100644 --- a/cmd/chisel/cmd_cut.go +++ b/cmd/chisel/cmd_cut.go @@ -49,7 +49,7 @@ func (cmd *cmdCut) Execute(args []string) error { sliceKeys[i] = sliceKey } - release, _, err := getRelease(cmd.Release) + release, _, err := readOrFetchRelease(cmd.Release) if err != nil { return err } diff --git a/cmd/chisel/cmd_info.go b/cmd/chisel/cmd_info.go index 47f3330c..69ca9967 100644 --- a/cmd/chisel/cmd_info.go +++ b/cmd/chisel/cmd_info.go @@ -46,7 +46,7 @@ func (cmd *infoCmd) Execute(args []string) error { return ErrExtraArgs } - release, _, err := getRelease(cmd.Release) + release, _, err := readOrFetchRelease(cmd.Release) if err != nil { return err } diff --git a/cmd/chisel/helpers.go b/cmd/chisel/helpers.go index 5a3b886c..14b9bd8d 100644 --- a/cmd/chisel/helpers.go +++ b/cmd/chisel/helpers.go @@ -41,9 +41,12 @@ func readReleaseInfo() (label, version string, err error) { return "", "", fmt.Errorf("cannot infer release via /etc/lsb-release, see the --release option") } -// getRelease returns the release and release label (e.g. ubuntu-22.04 or -// /path/to/release/dir/ if a directory was passed as input). -func getRelease(releaseStr string) (release *setup.Release, releaseLabel string, err error) { +// readOrFetchRelease takes a release branch name or a release directory path. +// It fetches or reads the chisel-release depending on the nature of input and +// returns the release and release label. +// If the input is empty, it tries to read the release label from the host +// system and fetch the chisel-release accordingly. +func readOrFetchRelease(releaseStr string) (release *setup.Release, releaseLabel string, err error) { if strings.Contains(releaseStr, "/") { release, err = setup.ReadRelease(releaseStr) releaseLabel = releaseStr