Skip to content

Commit

Permalink
autocomplete and vendor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
decleaver committed Mar 12, 2024
1 parent 71b5b94 commit 9453ad9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 61 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.6
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/defenseunicorns/maru-runner v0.0.1
github.com/defenseunicorns/maru-runner v0.0.2
github.com/defenseunicorns/zarf v0.32.4
github.com/fsnotify/fsnotify v1.7.0
github.com/goccy/go-yaml v1.11.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
github.com/defenseunicorns/maru-runner v0.0.1 h1:0SPiaXbPKnv7bjsUW2f7rPiIMmd3YLfT9+wQe4810K8=
github.com/defenseunicorns/maru-runner v0.0.1/go.mod h1:3K+JeLpud+rb8vC+nPFaTNjhqW40++6qFKKVTBEEzQM=
github.com/defenseunicorns/maru-runner v0.0.2 h1:aZ/MCryY3Dp+u14nhGrvOXVnZI3DYY3ytjFdfHnyqY4=
github.com/defenseunicorns/maru-runner v0.0.2/go.mod h1:3K+JeLpud+rb8vC+nPFaTNjhqW40++6qFKKVTBEEzQM=
github.com/defenseunicorns/zarf v0.32.4 h1:3foCaUHUtAu8YId49j3u+EVknaTB8ERaQ9J6Do+bAwc=
github.com/defenseunicorns/zarf v0.32.4/go.mod h1:f4H7al7qnj5VXfkUkB/CcepVW/DA/O5tvAy8TWv9aT8=
github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da h1:ZOjWpVsFZ06eIhnh4mkaceTiVoktdU67+M7KDHJ268M=
Expand Down
54 changes: 0 additions & 54 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"

runnerCLI "github.com/defenseunicorns/maru-runner/src/cmd"
runnerConfig "github.com/defenseunicorns/maru-runner/src/config"

"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/config/lang"
"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/uds-cli/src/types"
zarfCLI "github.com/defenseunicorns/zarf/src/cmd"
"github.com/defenseunicorns/zarf/src/cmd/common"
zarfConfig "github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -69,53 +62,6 @@ func RootCmd() *cobra.Command {
}

func init() {
// grab Zarf version to make Zarf library checks happy
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/defenseunicorns/zarf" {
zarfConfig.CLIVersion = strings.Split(dep.Version, "v")[1]
}
}
}

// vendored Zarf command
if len(os.Args) > 1 && (os.Args[1] == "zarf" || os.Args[1] == "z") {
zarfCmd := &cobra.Command{
Use: "zarf COMMAND",
Aliases: []string{"z"},
Run: func(_ *cobra.Command, _ []string) {
os.Args = os.Args[1:] // grab 'zarf' and onward from the CLI args
zarfCLI.Execute()
},
DisableFlagParsing: true,
}
rootCmd.AddCommand(zarfCmd)

// disable UDS log file for Zarf commands bc Zarf has its own log file
config.SkipLogFile = true
return
}

// vendored run command
if len(os.Args) > 1 && (os.Args[1] == "run" || os.Args[1] == "r") {
runnerCmd := &cobra.Command{
Use: "run",
Aliases: []string{"r"},
Run: func(_ *cobra.Command, _ []string) {
os.Args = os.Args[1:] // grab 'run' and onward from the CLI args
runnerConfig.CmdPrefix = "uds" // use vendored Zarf inside the runner
runnerConfig.EnvPrefix = "uds"
runnerCLI.RootCmd().SetArgs(os.Args)
runnerCLI.Execute()
},
DisableFlagParsing: true,
}
rootCmd.AddCommand(runnerCmd)

// disable UDS log file for the runner because the runner has its own log file
config.SkipLogFile = true
return
}

initViper()

Expand Down
68 changes: 68 additions & 0 deletions src/cmd/vendored.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

package cmd

import (
"os"
"runtime/debug"
"strings"

runnerCLI "github.com/defenseunicorns/maru-runner/src/cmd"
runnerConfig "github.com/defenseunicorns/maru-runner/src/config"

"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/config/lang"
zarfCLI "github.com/defenseunicorns/zarf/src/cmd"
zarfConfig "github.com/defenseunicorns/zarf/src/config"
"github.com/spf13/cobra"
)

var runnerCmd = &cobra.Command{
Use: "run",
Aliases: []string{"r"},
Short: lang.CmdRunShort,
Run: func(_ *cobra.Command, _ []string) {
os.Args = os.Args[1:] // grab 'run' and onward from the CLI args
runnerConfig.CmdPrefix = "uds" // use vendored Zarf inside the runner
runnerConfig.EnvPrefix = "uds"
runnerCLI.RootCmd().SetArgs(os.Args)
runnerCLI.Execute()
},
DisableFlagParsing: true,
ValidArgsFunction: func(cmd *cobra.Command, tasks []string, task string) ([]string, cobra.ShellCompDirective) {
return runnerCLI.ListAutoCompleteTasks(cmd, tasks, task)
},
}

var zarfCmd = &cobra.Command{
Use: "zarf COMMAND",
Aliases: []string{"z"},
Short: lang.CmdZarfShort,
Run: func(_ *cobra.Command, _ []string) {
os.Args = os.Args[1:] // grab 'zarf' and onward from the CLI args
zarfCLI.Execute()
},
DisableFlagParsing: true,
}

func init() {
// grab Zarf version to make Zarf library checks happy
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/defenseunicorns/zarf" {
zarfConfig.CLIVersion = strings.Split(dep.Version, "v")[1]
}
}
}

// vendored Zarf command
if len(os.Args) > 1 && (os.Args[1] == "zarf" || os.Args[1] == "z") && (os.Args[1] == "run" || os.Args[1] == "r") {
// disable UDS log file for zarf and run commands bc they have their own log file
config.SkipLogFile = true
}

initViper()
rootCmd.AddCommand(runnerCmd)
rootCmd.AddCommand(zarfCmd)
}
8 changes: 4 additions & 4 deletions src/config/lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const (
CmdInternalConfigSchemaErr = "Unable to generate the uds-bundle.yaml schema"

// uds run
CmdRunFlag = "Name and location of task file to run"
CmdRunSetVarFlag = "Set a runner variable from the command line (KEY=value)"
CmdRunWithVarFlag = "Set the inputs for a task from the command line (KEY=value)"
CmdRunList = "List available tasks in a task file"
CmdRunShort = "Run a task using maru-runner"

// uds zarf
CmdZarfShort = "Run a zarf command"
)

0 comments on commit 9453ad9

Please sign in to comment.