diff --git a/cmd/crowdsec-cli/clihub/hub.go b/cmd/crowdsec-cli/clihub/hub.go index 879508102..0a33d4934 100644 --- a/cmd/crowdsec-cli/clihub/hub.go +++ b/cmd/crowdsec-cli/clihub/hub.go @@ -46,6 +46,7 @@ cscli hub upgrade`, DisableAutoGenTag: true, } + cmd.AddCommand(cli.newBranchCmd()) cmd.AddCommand(cli.newListCmd()) cmd.AddCommand(cli.newUpdateCmd()) cmd.AddCommand(cli.newUpgradeCmd()) @@ -84,6 +85,28 @@ func (cli *cliHub) List(out io.Writer, hub *cwhub.Hub, all bool) error { return nil } +func (cli *cliHub) newBranchCmd() *cobra.Command { + var all bool + + cmd := &cobra.Command{ + Use: "branch", + Short: "Show selected hub branch", + Long: "Display the hub branch to be used, depending on configuration and crowdsec version", + Args: args.NoArgs, + DisableAutoGenTag: true, + RunE: func(cmd *cobra.Command, _ []string) error { + branch := require.HubBranch(cmd.Context(), cli.cfg()) + fmt.Println(branch) + return nil + }, + } + + flags := cmd.Flags() + flags.BoolVarP(&all, "all", "a", false, "List all available items, including those not installed") + + return cmd +} + func (cli *cliHub) newListCmd() *cobra.Command { var all bool diff --git a/test/lib/config/config-global b/test/lib/config/config-global index 9b2b71c1d..83d95e68e 100755 --- a/test/lib/config/config-global +++ b/test/lib/config/config-global @@ -61,6 +61,19 @@ config_prepare() { .api.server.listen_socket="/run/crowdsec.sock" | .config_paths.config_dir |= sub("/$", "") ' "${CONFIG_DIR}/config.yaml" + + # pin the branch to avoid having to query the last version repeatedly. + # this means the fixture could possibly go stale (i.e. use the wrong branch) if a new version is released, + # but that shouldn't impact the tests anyway. + + HUB_BRANCH=$("$CSCLI" hub branch 2>/dev/null) + export HUB_BRANCH + + echo "Setting up tests with hub branch $HUB_BRANCH" + + # need a working config, so we do it as a separate step. + + yq -i e '.cscli.hub_branch=strenv(HUB_BRANCH)' "${CONFIG_DIR}/config.yaml" } make_init_data() { diff --git a/test/lib/config/config-local b/test/lib/config/config-local index 3e3c806b6..54ac8550c 100755 --- a/test/lib/config/config-local +++ b/test/lib/config/config-local @@ -98,6 +98,19 @@ config_generate() { .api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" | del(.api.server.online_client) ' ../config/config.yaml >"${CONFIG_DIR}/config.yaml" + + # pin the branch to avoid having to query the last version repeatedly. + # this means the fixture could possibly go stale (i.e. use the wrong branch) if a new version is released, + # but that shouldn't impact the tests anyway. + + HUB_BRANCH=$("$CSCLI" hub branch 2>/dev/null) + export HUB_BRANCH + + echo "Setting up tests with hub branch $HUB_BRANCH" + + # need a working config, so we do it as a separate step. + + yq -i e '.cscli.hub_branch=strenv(HUB_BRANCH)' "${CONFIG_DIR}/config.yaml" } make_init_data() {