2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-01-24 10:08:04 -05:00
|
|
|
// Package cmd contains the cdbg CLI.
|
2022-03-22 11:03:15 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-08-07 05:40:48 -04:00
|
|
|
"fmt"
|
2022-03-22 11:03:15 -04:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-08-24 07:43:23 -04:00
|
|
|
func newRootCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "cdbg",
|
|
|
|
Short: "Constellation debugging client",
|
|
|
|
Long: `cdbg is the constellation debugging client.
|
2022-10-21 04:16:44 -04:00
|
|
|
It connects to Constellation instances running debugd and deploys a self-compiled version of the bootstrapper.`,
|
2023-08-07 05:40:48 -04:00
|
|
|
PersistentPreRunE: preRunRoot,
|
2022-08-24 07:43:23 -04:00
|
|
|
}
|
2023-08-07 05:40:48 -04:00
|
|
|
cmd.PersistentFlags().StringP("workspace", "C", "", "path to the Constellation workspace")
|
2023-01-31 05:45:31 -05:00
|
|
|
cmd.PersistentFlags().Bool("force", false, "disables version validation errors - might result in corrupted clusters")
|
|
|
|
|
2023-08-07 05:40:48 -04:00
|
|
|
must(cmd.MarkPersistentFlagDirname("workspace"))
|
|
|
|
|
2022-08-24 07:43:23 -04:00
|
|
|
cmd.AddCommand(newDeployCmd())
|
|
|
|
return cmd
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute starts the CLI.
|
|
|
|
func Execute() {
|
2022-08-24 07:43:23 -04:00
|
|
|
cmd := newRootCmd()
|
|
|
|
if err := cmd.Execute(); err != nil {
|
2022-03-22 11:03:15 -04:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2023-08-07 05:40:48 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|