Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocomplete and vendor refactor #502

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)
Loading