cdbg: implement workspace / "-C" flag and "--bindir" (#2170)

This commit is contained in:
Malte Poll 2023-08-07 11:40:48 +02:00 committed by GitHub
parent 9dcad0ed16
commit bd26e6bae7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 12 deletions

View file

@ -8,9 +8,9 @@ SPDX-License-Identifier: AGPL-3.0-only
package cmd
import (
"fmt"
"os"
"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/spf13/cobra"
)
@ -20,10 +20,13 @@ func newRootCmd() *cobra.Command {
Short: "Constellation debugging client",
Long: `cdbg is the constellation debugging client.
It connects to Constellation instances running debugd and deploys a self-compiled version of the bootstrapper.`,
PersistentPreRunE: preRunRoot,
}
cmd.PersistentFlags().String("config", constants.ConfigFilename, "Constellation config file")
cmd.PersistentFlags().StringP("workspace", "C", "", "path to the Constellation workspace")
cmd.PersistentFlags().Bool("force", false, "disables version validation errors - might result in corrupted clusters")
must(cmd.MarkPersistentFlagDirname("workspace"))
cmd.AddCommand(newDeployCmd())
return cmd
}
@ -35,3 +38,28 @@ func Execute() {
os.Exit(1)
}
}
func preRunRoot(cmd *cobra.Command, _ []string) error {
cmd.SilenceUsage = true
workspace, err := cmd.Flags().GetString("workspace")
if err != nil {
return fmt.Errorf("getting workspace flag: %w", err)
}
// Change to workspace directory if set.
if workspace != "" {
if err := os.Chdir(workspace); err != nil {
return fmt.Errorf("changing from current directory to workspace %q: %w", workspace, err)
}
}
return nil
}
func must(err error) {
if err == nil {
return
}
panic(err)
}