mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-10 16:00:19 -04:00
cdbg: implement workspace / "-C" flag and "--bindir" (#2170)
This commit is contained in:
parent
9dcad0ed16
commit
bd26e6bae7
2 changed files with 49 additions and 12 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue