Skip to content

Commit

Permalink
moved vpp-probe handling to swctl dependency command and also added a…
Browse files Browse the repository at this point in the history
…gentctl handling in similar way (#145)

moved vpp-probe handling to swctl dependency command and also added agentctl handling in similar way

Also:
-replaced function for printing into swctl console to remove warnings about generally ignored edge case error of writing
-renamed vpp config getter command in swctl to prevent confusion with stonework startup config

Signed-off-by: Filip Gschwandtner <[email protected]>
  • Loading branch information
fgschwan authored Oct 19, 2023
1 parent a7f3e74 commit 7aa1cc3
Show file tree
Hide file tree
Showing 14 changed files with 534 additions and 307 deletions.
32 changes: 3 additions & 29 deletions cmd/swctl/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import (
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/docker/cli/cli/streams"
"github.com/moby/term"
"github.com/sirupsen/logrus"

"go.pantheon.tech/stonework/client"
)

// TODO: to be refactored:
// - refactor the usage of external apps: agentctl, vpp-probe

// Cli is a client API for CLI application.
type Cli interface {
Initialize(opts *GlobalOptions) error
Expand All @@ -37,14 +31,16 @@ type CLI struct {
client client.API

entities []Entity
vppProbePath string
globalOptions *GlobalOptions

out *streams.Out
err io.Writer
in *streams.In

appName string
// customizations is the generic way how to pass CLI customizations without extending the API. It should
// be used for small modifications or changes that are not worthy to change the CLI API.
customizations map[string]interface{}
}

// NewCli returns a new CLI instance. It accepts CliOption for customization.
Expand Down Expand Up @@ -90,14 +86,6 @@ func (cli *CLI) Initialize(opts *GlobalOptions) (err error) {
return fmt.Errorf("loading embedded entity files failed: %w", err)
}

// get vpp-probe
vppProbePath, err := initVppProbe()
if err != nil {
logrus.Errorf("vpp-probe error: %v", err)
} else {
cli.vppProbePath = vppProbePath
}

return nil
}

Expand All @@ -110,20 +98,6 @@ func initClient(opts ...client.Option) (*client.Client, error) {
return c, nil
}

func initVppProbe() (string, error) {
if os.Getenv(EnvVarVppProbeNoDownload) != "" {
logrus.Debugf("vpp-probe download disabled by user")
return "", fmt.Errorf("downloading disabled by user")
}

vppProbePath, err := downloadVppProbe()
if err != nil {
return "", fmt.Errorf("downloading vpp-probe failed: %w", err)
}

return vppProbePath, nil
}

func (cli *CLI) Client() client.API {
return cli.client
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/swctl/app/cli_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ func WithClient(c client.API) CliOption {
return nil
}
}

// WithCustomizations sets the generic customizations of the CLI.
func WithCustomizations(customizations map[string]interface{}) CliOption {
return func(cli *CLI) error {
cli.customizations = customizations
return nil
}
}
7 changes: 3 additions & 4 deletions cmd/swctl/app/cmd_config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package app

import (
"fmt"

"github.com/gookit/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -53,7 +52,7 @@ func runConfigCmd(cli Cli, opts ConfigCmdOptions) error {
return err
}

fmt.Fprintln(cli.Err(), stderr)
fmt.Fprintln(cli.Out(), stdout)
color.Fprintln(cli.Err(), stderr)
color.Fprintln(cli.Out(), stdout)
return nil
}
Loading

0 comments on commit 7aa1cc3

Please sign in to comment.