diff --git a/pkg/app/run.go b/pkg/app/run.go index 06a624e77..d86b6df54 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -14,11 +14,13 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/kingpin" "github.com/fatih/color" + "github.com/hashicorp/cap/oidc" "github.com/skratchdot/open-golang/open" "github.com/fastly/cli/pkg/api" "github.com/fastly/cli/pkg/auth" "github.com/fastly/cli/pkg/cmd" + "github.com/fastly/cli/pkg/commands" "github.com/fastly/cli/pkg/commands/compute" "github.com/fastly/cli/pkg/commands/update" "github.com/fastly/cli/pkg/commands/version" @@ -37,17 +39,17 @@ import ( // Run kick starts the CLI application. func Run(args []string, stdin io.Reader) error { - opts, err := Init(args, stdin) + data, err := Init(args, stdin) if err != nil { return fmt.Errorf("failed to initialise application: %w", err) } - return Exec(opts) + return Exec(data) } // Init constructs all the required objects and data for Exec(). // // NOTE: We define as a package level variable so we can mock output for tests. -var Init = func(args []string, stdin io.Reader) (RunOpts, error) { +var Init = func(args []string, stdin io.Reader) (*global.Data, error) { // Parse the arguments provided by the user via the command-line interface. args = args[1:] @@ -91,7 +93,7 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { cfg.SetAutoYes(autoYes) cfg.SetNonInteractive(nonInteractive) if err := cfg.Read(config.FilePath, in, out, fsterr.Log, verboseOutput); err != nil { - return RunOpts{}, err + return nil, err } // Extract user's project configuration from the fastly.toml manifest. @@ -107,29 +109,37 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { // We do this here so that we can mock the values in our test suite. req, err := http.NewRequest(http.MethodGet, auth.OIDCMetadata, nil) if err != nil { - return RunOpts{}, fmt.Errorf("failed to construct request object for OpenID Connect .well-known metadata: %w", err) + return nil, fmt.Errorf("failed to construct request object for OpenID Connect .well-known metadata: %w", err) } resp, err := httpClient.Do(req) if err != nil { - return RunOpts{}, fmt.Errorf("failed to request OpenID Connect .well-known metadata: %w", err) + return nil, fmt.Errorf("failed to request OpenID Connect .well-known metadata: %w", err) } openIDConfig, err := io.ReadAll(resp.Body) if err != nil { - return RunOpts{}, fmt.Errorf("failed to read OpenID Connect .well-known metadata: %w", err) + return nil, fmt.Errorf("failed to read OpenID Connect .well-known metadata: %w", err) } _ = resp.Body.Close() var wellknown auth.WellKnownEndpoints err = json.Unmarshal(openIDConfig, &wellknown) if err != nil { - return RunOpts{}, fmt.Errorf("failed to unmarshal OpenID Connect .well-known metadata: %w", err) + return nil, fmt.Errorf("failed to unmarshal OpenID Connect .well-known metadata: %w", err) } result := make(chan auth.AuthorizationResult) router := http.NewServeMux() + verifier, err := oidc.NewCodeVerifier() + if err != nil { + return nil, fsterr.RemediationError{ + Inner: fmt.Errorf("failed to generate a code verifier for SSO authentication server: %w", err), + Remediation: auth.Remediation, + } + } authServer := &auth.Server{ DebugMode: e.DebugMode, HTTPClient: httpClient, Result: result, Router: router, + Verifier: verifier, WellKnownEndpoints: wellknown, } router.HandleFunc("/callback", authServer.HandleCallback()) @@ -142,7 +152,7 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { return client, err } - versioners := Versioners{ + versioners := global.Versioners{ CLI: github.New(github.Opts{ HTTPClient: httpClient, Org: "fastly", @@ -166,11 +176,11 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { }), } - return RunOpts{ + return &global.Data{ APIClientFactory: factory, Args: args, AuthServer: authServer, - ConfigFile: cfg, + Config: cfg, ConfigPath: config.FilePath, Env: e, ErrLog: fsterr.Log, @@ -178,9 +188,9 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { HTTPClient: httpClient, Manifest: &md, Opener: open.Run, - Stdin: in, - Stdout: out, + Output: out, Versioners: versioners, + Input: in, }, nil } @@ -194,23 +204,10 @@ var Init = func(args []string, stdin io.Reader) (RunOpts, error) { // The Exec helper should NOT output any error-related information to the out // io.Writer. All error-related information should be encoded into an error type // and returned to the caller. This includes usage text. -func Exec(opts RunOpts) error { - // The g will hold generally-applicable configuration parameters - // from a variety of sources, and is provided to each concrete command. - g := global.Data{ - Config: opts.ConfigFile, - ConfigPath: opts.ConfigPath, - Env: opts.Env, - ErrLog: opts.ErrLog, - ExecuteWasmTools: opts.ExecuteWasmTools, - HTTPClient: opts.HTTPClient, - Manifest: *opts.Manifest, - Output: opts.Stdout, - } - - app := configureKingpin(opts.Stdout, &g) - commands := defineCommands(app, &g, *opts.Manifest, opts.Opener, opts.AuthServer, opts.Versioners, opts.APIClientFactory) - command, commandName, err := processCommandInput(opts.Args, opts.Stdout, app, &g, commands) +func Exec(data *global.Data) error { + app := configureKingpin(data) + commands := commands.Define(app, data) + command, commandName, err := processCommandInput(data, app, commands) if err != nil { return err } @@ -230,87 +227,52 @@ func Exec(opts RunOpts) error { // FIXME: Tweak messaging before for 10.7.0 // To learn more about what data is being collected, why, and how to disable it: https://developer.fastly.com/reference/cli/ - metadataDisable, _ := strconv.ParseBool(g.Env.WasmMetadataDisable) - if slices.Contains(opts.Args, "--metadata-enable") && !metadataDisable && !g.Config.CLI.MetadataNoticeDisplayed && commandCollectsData(commandName) { - text.Important(g.Output, "The Fastly CLI is configured to collect data related to Wasm builds (e.g. compilation times, resource usage, and other non-identifying data). To learn more about our data & privacy policies visit https://www.fastly.com/trust. Join the conversation https://bit.ly/wasm-metadata") - text.Break(g.Output) - g.Config.CLI.MetadataNoticeDisplayed = true - err := g.Config.Write(g.ConfigPath) + metadataDisable, _ := strconv.ParseBool(data.Env.WasmMetadataDisable) + if slices.Contains(data.Args, "--metadata-enable") && !metadataDisable && !data.Config.CLI.MetadataNoticeDisplayed && commandCollectsData(commandName) { + text.Important(data.Output, "The Fastly CLI is configured to collect data related to Wasm builds (e.g. compilation times, resource usage, and other non-identifying data). To learn more about our data & privacy policies visit https://www.fastly.com/trust. Join the conversation https://bit.ly/wasm-metadata") + text.Break(data.Output) + data.Config.CLI.MetadataNoticeDisplayed = true + err := data.Config.Write(data.ConfigPath) if err != nil { return fmt.Errorf("failed to persist change to metadata notice: %w", err) } time.Sleep(5 * time.Second) // this message is only displayed once so give the user a chance to see it before it possibly scrolls off screen } - if g.Flags.Quiet { - opts.Manifest.File.SetQuiet(true) + if data.Flags.Quiet { + data.Manifest.File.SetQuiet(true) } - apiEndpoint, endpointSource := g.APIEndpoint() - if g.Verbose() { - displayAPIEndpoint(apiEndpoint, endpointSource, opts.Stdout) + apiEndpoint, endpointSource := data.APIEndpoint() + if data.Verbose() { + displayAPIEndpoint(apiEndpoint, endpointSource, data.Output) } - token, err := processToken(commands, commandName, opts.Manifest, &g, opts.Stdin, opts.Stdout) + token, err := processToken(commands, commandName, data) if err != nil { return fmt.Errorf("failed to process token: %w", err) } - g.APIClient, g.RTSClient, err = configureClients(token, apiEndpoint, opts.APIClientFactory, g.Flags.Debug) + data.APIClient, data.RTSClient, err = configureClients(token, apiEndpoint, data.APIClientFactory, data.Flags.Debug) if err != nil { - g.ErrLog.Add(err) + data.ErrLog.Add(err) return fmt.Errorf("error constructing client: %w", err) } - f := checkForUpdates(opts.Versioners.CLI, commandName, g.Flags.Quiet) - defer f(opts.Stdout) + f := checkForUpdates(data.Versioners.CLI, commandName, data.Flags.Quiet) + defer f(data.Output) - return command.Exec(opts.Stdin, opts.Stdout) + return command.Exec(data.Input, data.Output) } -// RunOpts represent arguments we can mock at runtime. -type RunOpts struct { - // APIClientFactory is a factory function for creating an api.Interface type. - APIClientFactory APIClientFactory - // Args are the command line arguments provided by the user. - Args []string - // AuthServer is an instance of the authentication server type. - // Used for interacting with Fastly's SSO/OAuth authentication provider. - AuthServer auth.Starter - // ConfigFile is an instance of the CLI application config. - ConfigFile config.File - // ConfigPath is the location of the CLI application config. - ConfigPath string - // Env is an instance of the supported environment variables. - Env config.Environment - // ErrLog is an instance of a error log recorder. - ErrLog fsterr.LogInterface - // ExecuteWasmTools is a function that calls wasm-tools executable. - // Designed to be used for mocking in the CLI test suite. - ExecuteWasmTools func(bin string, args []string) error - // HTTPClient is a standard HTTP client. - HTTPClient api.HTTPClient - // Manifest is the fastly.toml manifest file. - Manifest *manifest.Data - // Opener is a function that can open a browser window. - Opener func(string) error - // Stdin is the standard input destination. - Stdin io.Reader - // Stdout is the standard output destination. - Stdout io.Writer - // Versioners contains multiple software versioning checkers. - // e.g. Check for latest CLI or Viceroy version. - Versioners Versioners -} - -func configureKingpin(out io.Writer, g *global.Data) *kingpin.Application { +func configureKingpin(data *global.Data) *kingpin.Application { // Set up the main application root, including global flags, and then each // of the subcommands. Note that we deliberately don't use some of the more // advanced features of the kingpin.Application flags, like env var // bindings, because we need to do things like track where a config // parameter came from. app := kingpin.New("fastly", "A tool to interact with the Fastly API") - app.Writers(out, io.Discard) // don't let kingpin write error output + app.Writers(data.Output, io.Discard) // don't let kingpin write error output app.UsageContext(&kingpin.UsageContext{ Template: VerboseUsageTemplate, Funcs: UsageTemplateFuncs, @@ -330,17 +292,17 @@ func configureKingpin(out io.Writer, g *global.Data) *kingpin.Application { // Kingpin will otherwise trigger a runtime panic 🎉 // Interestingly, short flags can be reused but only across subcommands. tokenHelp := fmt.Sprintf("Fastly API token (or via %s)", env.APIToken) - app.Flag("accept-defaults", "Accept default options for all interactive prompts apart from Yes/No confirmations").Short('d').BoolVar(&g.Flags.AcceptDefaults) - app.Flag("account", "Fastly Accounts endpoint").Hidden().StringVar(&g.Flags.Account) - app.Flag("auto-yes", "Answer yes automatically to all Yes/No confirmations. This may suppress security warnings").Short('y').BoolVar(&g.Flags.AutoYes) + app.Flag("accept-defaults", "Accept default options for all interactive prompts apart from Yes/No confirmations").Short('d').BoolVar(&data.Flags.AcceptDefaults) + app.Flag("account", "Fastly Accounts endpoint").Hidden().StringVar(&data.Flags.Account) + app.Flag("auto-yes", "Answer yes automatically to all Yes/No confirmations. This may suppress security warnings").Short('y').BoolVar(&data.Flags.AutoYes) // IMPORTANT: `--debug` is a built-in Kingpin flag so we can't use that. - app.Flag("debug-mode", "Print API request and response details (NOTE: can disrupt the normal CLI flow output formatting)").BoolVar(&g.Flags.Debug) - app.Flag("endpoint", "Fastly API endpoint").Hidden().StringVar(&g.Flags.Endpoint) - app.Flag("non-interactive", "Do not prompt for user input - suitable for CI processes. Equivalent to --accept-defaults and --auto-yes").Short('i').BoolVar(&g.Flags.NonInteractive) - app.Flag("profile", "Switch account profile for single command execution (see also: 'fastly profile switch')").Short('o').StringVar(&g.Flags.Profile) - app.Flag("quiet", "Silence all output except direct command output. This won't prevent interactive prompts (see: --accept-defaults, --auto-yes, --non-interactive)").Short('q').BoolVar(&g.Flags.Quiet) - app.Flag("token", tokenHelp).HintAction(env.Vars).Short('t').StringVar(&g.Flags.Token) - app.Flag("verbose", "Verbose logging").Short('v').BoolVar(&g.Flags.Verbose) + app.Flag("debug-mode", "Print API request and response details (NOTE: can disrupt the normal CLI flow output formatting)").BoolVar(&data.Flags.Debug) + app.Flag("endpoint", "Fastly API endpoint").Hidden().StringVar(&data.Flags.Endpoint) + app.Flag("non-interactive", "Do not prompt for user input - suitable for CI processes. Equivalent to --accept-defaults and --auto-yes").Short('i').BoolVar(&data.Flags.NonInteractive) + app.Flag("profile", "Switch account profile for single command execution (see also: 'fastly profile switch')").Short('o').StringVar(&data.Flags.Profile) + app.Flag("quiet", "Silence all output except direct command output. This won't prevent interactive prompts (see: --accept-defaults, --auto-yes, --non-interactive)").Short('q').BoolVar(&data.Flags.Quiet) + app.Flag("token", tokenHelp).HintAction(env.Vars).Short('t').StringVar(&data.Flags.Token) + app.Flag("verbose", "Verbose logging").Short('v').BoolVar(&data.Flags.Verbose) return app } @@ -360,13 +322,13 @@ func configureKingpin(out io.Writer, g *global.Data) *kingpin.Application { // // Finally, we check if there is a profile override in place (e.g. set via the // --profile flag or using the `profile` field in the fastly.toml manifest). -func processToken(commands []cmd.Command, commandName string, m *manifest.Data, g *global.Data, in io.Reader, out io.Writer) (token string, err error) { +func processToken(commands []cmd.Command, commandName string, data *global.Data) (token string, err error) { warningMessage := "No API token could be found" var tokenSource lookup.Source - token, tokenSource = g.Token() + token, tokenSource = data.Token() // Check if token is from fastly.toml [profile] and refresh if expired. - tokenSource, warningMessage, err = checkProfileToken(tokenSource, commandName, warningMessage, out, g) + tokenSource, warningMessage, err = checkProfileToken(tokenSource, commandName, warningMessage, data) if err != nil { return token, fmt.Errorf("failed to check profile token: %w", err) } @@ -374,17 +336,17 @@ func processToken(commands []cmd.Command, commandName string, m *manifest.Data, // If there's no token available, and we need one for the invoked command, // then we'll trigger the SSO authentication flow. if tokenSource == lookup.SourceUndefined && commandRequiresToken(commandName) { - token, tokenSource, err = ssoAuthentication(tokenSource, token, warningMessage, commands, in, out, g) + token, tokenSource, err = ssoAuthentication(tokenSource, token, warningMessage, commands, data) if err != nil { return token, fmt.Errorf("failed to check profile token: %w", err) } } - if g.Verbose() { - displayToken(tokenSource, m.File.Profile, *g, out) + if data.Verbose() { + displayToken(tokenSource, data) } - if !g.Flags.Quiet { - checkConfigPermissions(commandName, tokenSource, out) + if !data.Flags.Quiet { + checkConfigPermissions(commandName, tokenSource, data.Output) } return token, nil @@ -397,8 +359,7 @@ func processToken(commands []cmd.Command, commandName string, m *manifest.Data, func checkProfileToken( tokenSource lookup.Source, commandName, warningMessage string, - out io.Writer, - g *global.Data, + data *global.Data, ) (lookup.Source, string, error) { if tokenSource == lookup.SourceFile && commandRequiresToken(commandName) { var ( @@ -407,14 +368,14 @@ func checkProfileToken( name, profileName string ) switch { - case g.Flags.Profile != "": // --profile - profileName = g.Flags.Profile - case g.Manifest.File.Profile != "": // `profile` field in fastly.toml - profileName = g.Manifest.File.Profile + case data.Flags.Profile != "": // --profile + profileName = data.Flags.Profile + case data.Manifest.File.Profile != "": // `profile` field in fastly.toml + profileName = data.Manifest.File.Profile default: profileName = "default" } - for name, profileData = range g.Config.Profiles { + for name, profileData = range data.Config.Profiles { if (profileName == "default" && profileData.Default) || name == profileName { // Once we find the default profile we can update the variable to be the // associated profile name so later on we can use that information to @@ -431,7 +392,7 @@ func checkProfileToken( } // Allow user to opt-in to SSO/OAuth so they can replace their long-lived token. - if shouldSkipSSO(profileName, profileData, out, g) { + if shouldSkipSSO(profileName, profileData, data) { return tokenSource, warningMessage, nil } @@ -453,18 +414,18 @@ func checkProfileToken( return tokenSource, warningMessage, nil } - if g.Flags.Verbose { - text.Info(out, "Your access token has now expired. We will attempt to refresh it") + if data.Flags.Verbose { + text.Info(data.Output, "Your access token has now expired. We will attempt to refresh it") } - accountEndpoint, _ := g.AccountEndpoint() - apiEndpoint, _ := g.APIEndpoint() + accountEndpoint, _ := data.AccountEndpoint() + apiEndpoint, _ := data.APIEndpoint() updatedJWT, err := auth.RefreshAccessToken(accountEndpoint, profileData.RefreshToken) if err != nil { return tokenSource, warningMessage, fmt.Errorf("failed to refresh access token: %w", err) } - email, at, err := auth.ValidateAndRetrieveAPIToken(accountEndpoint, apiEndpoint, updatedJWT.AccessToken, g.Env.DebugMode, g.HTTPClient) + email, at, err := auth.ValidateAndRetrieveAPIToken(accountEndpoint, apiEndpoint, updatedJWT.AccessToken, data.Env.DebugMode, data.HTTPClient) if err != nil { return tokenSource, warningMessage, fmt.Errorf("failed to validate JWT and retrieve API token: %w", err) } @@ -475,7 +436,7 @@ func checkProfileToken( // So after we get the refreshed access token, we check to see if the // refresh token that was returned by the API call has also changed when // compared to the refresh token stored in the CLI config file. - current := profile.Get(profileName, g.Config.Profiles) + current := profile.Get(profileName, data.Config.Profiles) if current == nil { return tokenSource, warningMessage, fmt.Errorf("failed to locate '%s' profile", profileName) } @@ -484,16 +445,16 @@ func checkProfileToken( refreshTokenCreated := current.RefreshTokenCreated refreshTokenTTL := current.RefreshTokenTTL if current.RefreshToken != updatedJWT.RefreshToken { - if g.Flags.Verbose { - text.Info(out, "Your refresh token was also updated") - text.Break(out) + if data.Flags.Verbose { + text.Info(data.Output, "Your refresh token was also updated") + text.Break(data.Output) } refreshToken = updatedJWT.RefreshToken refreshTokenCreated = now refreshTokenTTL = updatedJWT.RefreshExpiresIn } - ps, ok := profile.Edit(profileName, g.Config.Profiles, func(p *config.Profile) { + ps, ok := profile.Edit(profileName, data.Config.Profiles, func(p *config.Profile) { p.AccessToken = updatedJWT.AccessToken p.AccessTokenCreated = now p.AccessTokenTTL = updatedJWT.ExpiresIn @@ -509,9 +470,9 @@ func checkProfileToken( Remediation: "Run `fastly sso` to retry.", } } - g.Config.Profiles = ps - if err := g.Config.Write(g.ConfigPath); err != nil { - g.ErrLog.Add(err) + data.Config.Profiles = ps + if err := data.Config.Write(data.ConfigPath); err != nil { + data.ErrLog.Add(err) return tokenSource, warningMessage, fmt.Errorf("error saving config file: %w", err) } } @@ -523,18 +484,18 @@ func checkProfileToken( // shouldSkipSSO identifies if a config is a pre-v5 config and, if it is, // informs the user how they can use the SSO flow. It checks if the SSO // environment variable has been set and enables the SSO flow if so. -func shouldSkipSSO(profileName string, pd *config.Profile, out io.Writer, g *global.Data) bool { +func shouldSkipSSO(profileName string, pd *config.Profile, data *global.Data) bool { if noSSOToken(pd) { - return g.Env.UseSSO != "1" + return data.Env.UseSSO != "1" // FIXME: Put back messaging once SSO is GA. - // if g.Env.UseSSO == "1" { + // if data.Env.UseSSO == "1" { // return false // don't skip SSO // } - // if !g.Flags.Quiet { - // if g.Flags.Verbose { - // text.Break(out) + // if !data.Flags.Quiet { + // if data.Flags.Verbose { + // text.Break(data.Output) // } - // text.Important(out, "The Fastly API token used by the current '%s' profile is not a Fastly SSO (Single Sign-On) generated token. SSO-based tokens offer more security and convenience. To update your token, set `FASTLY_USE_SSO=1` before invoking the Fastly CLI. This will ensure the current profile is switched to using an SSO generated API token. Once the token has been switched over you no longer need to set `FASTLY_USE_SSO` for this profile (--token and FASTLY_API_TOKEN can still be used as overrides).\n\n", profileName) + // text.Important(data.Output, "The Fastly API token used by the current '%s' profile is not a Fastly SSO (Single Sign-On) generated token. SSO-based tokens offer more security and convenience. To update your token, set `FASTLY_USE_SSO=1` before invoking the Fastly CLI. This will ensure the current profile is switched to using an SSO generated API token. Once the token has been switched over you no longer need to set `FASTLY_USE_SSO` for this profile (--token and FASTLY_API_TOKEN can still be used as overrides).\n\n", profileName) // } // return true // skip SSO } @@ -556,18 +517,16 @@ func ssoAuthentication( tokenSource lookup.Source, token, warningMessage string, commands []cmd.Command, - in io.Reader, - out io.Writer, - g *global.Data, + data *global.Data, ) (string, lookup.Source, error) { for _, command := range commands { commandName := strings.Split(command.Name(), " ")[0] if commandName == "sso" { - if !g.Flags.AutoYes && !g.Flags.NonInteractive { - text.Important(out, "%s. We need to open your browser to authenticate you.", warningMessage) - text.Break(out) - cont, err := text.AskYesNo(out, text.BoldYellow("Do you want to continue? [y/N]: "), in) - text.Break(out) + if !data.Flags.AutoYes && !data.Flags.NonInteractive { + text.Important(data.Output, "%s. We need to open your browser to authenticate you.", warningMessage) + text.Break(data.Output) + cont, err := text.AskYesNo(data.Output, text.BoldYellow("Do you want to continue? [y/N]: "), data.Input) + text.Break(data.Output) if err != nil { return token, tokenSource, err } @@ -576,38 +535,38 @@ func ssoAuthentication( } } - g.SkipAuthPrompt = true // skip the same prompt in `sso` command flow - err := command.Exec(in, out) + data.SkipAuthPrompt = true // skip the same prompt in `sso` command flow + err := command.Exec(data.Input, data.Output) if err != nil { return token, tokenSource, fmt.Errorf("failed to authenticate: %w", err) } - text.Break(out) + text.Break(data.Output) break } } // Recheck for token (should be persisted to profile data). - token, tokenSource = g.Token() + token, tokenSource = data.Token() if tokenSource == lookup.SourceUndefined { return token, tokenSource, fsterr.ErrNoToken } return token, tokenSource, nil } -func displayToken(tokenSource lookup.Source, profileName string, g global.Data, out io.Writer) { - profileSource := determineProfile(profileName, g.Flags.Profile, g.Config.Profiles) +func displayToken(tokenSource lookup.Source, data *global.Data) { + profileSource := determineProfile(data.Manifest.File.Profile, data.Flags.Profile, data.Config.Profiles) switch tokenSource { case lookup.SourceFlag: - fmt.Fprintf(out, "Fastly API token provided via --token\n\n") + fmt.Fprintf(data.Output, "Fastly API token provided via --token\n\n") case lookup.SourceEnvironment: - fmt.Fprintf(out, "Fastly API token provided via %s\n\n", env.APIToken) + fmt.Fprintf(data.Output, "Fastly API token provided via %s\n\n", env.APIToken) case lookup.SourceFile: - fmt.Fprintf(out, "Fastly API token provided via config file (profile: %s)\n\n", profileSource) + fmt.Fprintf(data.Output, "Fastly API token provided via config file (profile: %s)\n\n", profileSource) case lookup.SourceUndefined, lookup.SourceDefault: fallthrough default: - fmt.Fprintf(out, "Fastly API token not provided\n\n") + fmt.Fprintf(data.Output, "Fastly API token not provided\n\n") } } @@ -642,7 +601,7 @@ func displayAPIEndpoint(endpoint string, endpointSource lookup.Source, out io.Wr } } -func configureClients(token, apiEndpoint string, acf APIClientFactory, debugMode bool) (apiClient api.Interface, rtsClient api.RealtimeStatsInterface, err error) { +func configureClients(token, apiEndpoint string, acf global.APIClientFactory, debugMode bool) (apiClient api.Interface, rtsClient api.RealtimeStatsInterface, err error) { apiClient, err = acf(token, apiEndpoint, debugMode) if err != nil { return nil, nil, fmt.Errorf("error constructing Fastly API client: %w", err) @@ -665,20 +624,6 @@ func checkForUpdates(av github.AssetVersioner, commandName string, quietMode boo } } -// APIClientFactory creates a Fastly API client (modeled as an api.Interface) -// from a user-provided API token. It exists as a type in order to parameterize -// the Run helper with it: in the real CLI, we can use NewClient from the Fastly -// API client library via RealClient; in tests, we can provide a mock API -// interface via MockClient. -type APIClientFactory func(token, apiEndpoint string, debugMode bool) (api.Interface, error) - -// Versioners represents all supported versioner types. -type Versioners struct { - CLI github.AssetVersioner - Viceroy github.AssetVersioner - WasmTools github.AssetVersioner -} - // determineProfile determines if the provided token was acquired via the // fastly.toml manifest, the --profile flag, or was a default profile from // within the config.toml application configuration. diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index e3b2e1322..89ce950ec 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/testutil" ) @@ -122,8 +123,8 @@ whoami outC <- buf.String() }() - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - return testutil.NewRunOpts(testcase.Args, &stdout), nil + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + return testutil.MockGlobalData(testcase.Args, &stdout), nil } err := app.Run(testcase.Args, nil) if err != nil { diff --git a/pkg/app/usage.go b/pkg/app/usage.go index 5b41acc51..c485dc1dc 100644 --- a/pkg/app/usage.go +++ b/pkg/app/usage.go @@ -208,10 +208,8 @@ const VerboseUsageTemplate = `{{define "FormatCommands" -}} // processing the incoming command request from the user, as well as handling // the various places where help output can be displayed. func processCommandInput( - args []string, - out io.Writer, + data *global.Data, app *kingpin.Application, - g *global.Data, commands []cmd.Command, ) (command cmd.Command, cmdName string, err error) { // As the `help` command model gets privately added as a side-effect of @@ -219,18 +217,18 @@ func processCommandInput( // Therefore, we have to manually parse the args slice here to check for the // existence of `help --format json`, if present we print usage JSON and // exit early. - if cmd.ArgsIsHelpJSON(args) { + if cmd.ArgsIsHelpJSON(data.Args) { j, err := UsageJSON(app) if err != nil { - g.ErrLog.Add(err) + data.ErrLog.Add(err) return command, cmdName, err } - fmt.Fprintf(out, "%s", j) - return command, strings.Join(args, ""), nil + fmt.Fprintf(data.Output, "%s", j) + return command, strings.Join(data.Args, ""), nil } // Use partial application to generate help output function. - help := displayHelp(g.ErrLog, args, app, out, io.Discard) + help := displayHelp(data.ErrLog, data.Args, app, data.Output, io.Discard) // Handle parse errors and display contextual usage if possible. Due to bugs // and an obsession for lots of output side-effects in the kingpin.Parse @@ -251,14 +249,14 @@ func processCommandInput( // But it's useful to have it implemented so it's ready to roll when we do. var vars map[string]any - if cmd.IsVerboseAndQuiet(args) { + if cmd.IsVerboseAndQuiet(data.Args) { return command, cmdName, fsterr.RemediationError{ Inner: errors.New("--verbose and --quiet flag provided"), Remediation: "Either remove both --verbose and --quiet flags, or one of them.", } } - if cmd.IsHelpFlagOnly(args) && len(args) == 1 { + if cmd.IsHelpFlagOnly(data.Args) && len(data.Args) == 1 { return command, cmdName, fsterr.SkipExitError{ Skip: true, Err: help(vars, nil), @@ -285,17 +283,17 @@ func processCommandInput( // // ctx.SelectedCommand will be nil if only a flag like --verbose or -v is // provided but with no actual command set so we check with IsGlobalFlagsOnly. - noargs := len(args) == 0 - globalFlagsOnly := cmd.IsGlobalFlagsOnly(args) - ctx, err := app.ParseContext(args) - if err != nil && !cmd.IsCompletion(args) || noargs || globalFlagsOnly { + noargs := len(data.Args) == 0 + globalFlagsOnly := cmd.IsGlobalFlagsOnly(data.Args) + ctx, err := app.ParseContext(data.Args) + if err != nil && !cmd.IsCompletion(data.Args) || noargs || globalFlagsOnly { if noargs || globalFlagsOnly { err = fmt.Errorf("command not specified") } return command, cmdName, help(vars, err) } - if len(args) == 1 && args[0] == "--" { + if len(data.Args) == 1 && data.Args[0] == "--" { return command, cmdName, fsterr.RemediationError{ Inner: errors.New("-- is invalid input when not followed by a positional argument"), Remediation: "If looking for help output try: `fastly help` for full command list or `fastly --help` for command summary.", @@ -311,14 +309,14 @@ func processCommandInput( // completion flag, as that depends on kingpin.Parse() being called, and so // the `ctx` is otherwise empty. var found bool - if !noargs && !globalFlagsOnly && !cmd.IsHelpOnly(args) && !cmd.IsHelpFlagOnly(args) && !cmd.IsCompletion(args) && !cmd.IsCompletionScript(args) { + if !noargs && !globalFlagsOnly && !cmd.IsHelpOnly(data.Args) && !cmd.IsHelpFlagOnly(data.Args) && !cmd.IsCompletion(data.Args) && !cmd.IsCompletionScript(data.Args) { command, found = cmd.Select(ctx.SelectedCommand.FullCommand(), commands) if !found { return command, cmdName, help(vars, err) } } - if cmd.ContextHasHelpFlag(ctx) && !cmd.IsHelpFlagOnly(args) { + if cmd.ContextHasHelpFlag(ctx) && !cmd.IsHelpFlagOnly(data.Args) { return command, cmdName, fsterr.SkipExitError{ Skip: true, Err: help(vars, nil), @@ -345,21 +343,21 @@ func processCommandInput( // caller passes --completion-bash because adding a command to the arguments // list in that scenario would cause Kingpin logic to fail (as it expects the // flag to be used on its own). - if cmd.IsCompletionScript(args) { - args = append(args, "shellcomplete") + if cmd.IsCompletionScript(data.Args) { + data.Args = append(data.Args, "shellcomplete") } - cmdName, err = app.Parse(args) + cmdName, err = app.Parse(data.Args) if err != nil { return command, "", help(vars, err) } // Restore output writers - app.Writers(out, io.Discard) + app.Writers(data.Output, io.Discard) // Kingpin generates shell completion as a side-effect of kingpin.Parse() so // we allow it to call os.Exit, only if a completion flag is present. - if cmd.IsCompletion(args) || cmd.IsCompletionScript(args) { + if cmd.IsCompletion(data.Args) || cmd.IsCompletionScript(data.Args) { app.Terminate(os.Exit) return command, "shell-autocomplete", nil } @@ -372,14 +370,14 @@ func processCommandInput( return command, cmdName, fsterr.SkipExitError{ Skip: true, Err: fsterr.RemediationError{ - Prefix: useFullHelpOutput(app, args, out).String(), + Prefix: useFullHelpOutput(app, data.Args, data.Output).String(), }, } } // Catch scenario where user wants to view help with the following format: // fastly --help - if cmd.IsHelpFlagOnly(args) { + if cmd.IsHelpFlagOnly(data.Args) { return command, cmdName, fsterr.SkipExitError{ Skip: true, Err: help(vars, nil), diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 1ca2a0f04..7378e038d 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -42,16 +42,17 @@ type WellKnownEndpoints struct { Token string `json:"token_endpoint"` } -// Starter defines the behaviour for the authentication server. -type Starter interface { +// Runner defines the behaviour for the authentication server. +type Runner interface { + // AuthURL returns a fully qualified authorization_endpoint. + // i.e. path + audience + scope + code_challenge etc. + AuthURL() (string, error) // GetResult returns the results channel GetResult() chan AuthorizationResult // SetAccountEndpoint sets the account endpoint. SetAccountEndpoint(endpoint string) // SetEndpoint sets the API endpoint. SetAPIEndpoint(endpoint string) - // SetVerifier sets the code verifier. - SetVerifier(verifier *oidc.S256Verifier) // Start starts a local server for handling authentication processing. Start() error } @@ -76,6 +77,25 @@ type Server struct { WellKnownEndpoints WellKnownEndpoints } +// AuthURL returns a fully qualified authorization_endpoint. +// i.e. path + audience + scope + code_challenge etc. +func (s Server) AuthURL() (string, error) { + challenge, err := oidc.CreateCodeChallenge(s.Verifier) + if err != nil { + return "", err + } + + authorizationURL := fmt.Sprintf( + "%s?audience=%s"+ + "&scope=openid"+ + "&response_type=code&client_id=%s"+ + "&code_challenge=%s"+ + "&code_challenge_method=S256&redirect_uri=%s", + s.WellKnownEndpoints.Auth, s.APIEndpoint, ClientID, challenge, RedirectURL) + + return authorizationURL, nil +} + // GetResult returns the result channel. func (s Server) GetResult() chan AuthorizationResult { return s.Result @@ -233,29 +253,6 @@ type AuthorizationResult struct { SessionToken string } -// GenVerifier creates a code verifier. -func GenVerifier() (*oidc.S256Verifier, error) { - return oidc.NewCodeVerifier() -} - -// GenURL constructs the required authorization_endpoint path. -func GenURL(accountEndpoint, apiEndpoint string, verifier *oidc.S256Verifier) (string, error) { - challenge, err := oidc.CreateCodeChallenge(verifier) - if err != nil { - return "", err - } - - authorizationURL := fmt.Sprintf( - "%s/realms/fastly/protocol/openid-connect/auth?audience=%s"+ - "&scope=openid"+ - "&response_type=code&client_id=%s"+ - "&code_challenge=%s"+ - "&code_challenge_method=S256&redirect_uri=%s", - accountEndpoint, apiEndpoint, ClientID, challenge, RedirectURL) - - return authorizationURL, nil -} - // GetJWT constructs and calls the token_endpoint path, returning a JWT // containing the access and refresh tokens and associated TTLs. func GetJWT(accountEndpoint, codeVerifier, authorizationCode string) (JWT, error) { diff --git a/pkg/commands/acl/acl_test.go b/pkg/commands/acl/acl_test.go index f481faaf4..1c634af8f 100644 --- a/pkg/commands/acl/acl_test.go +++ b/pkg/commands/acl/acl_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -88,8 +89,8 @@ func TestACLCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -167,8 +168,8 @@ func TestACLDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -232,8 +233,8 @@ func TestACLDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -301,8 +302,8 @@ func TestACLList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -394,8 +395,8 @@ func TestACLUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/acl/create.go b/pkg/commands/acl/create.go index aebdbcf79..bc8e46695 100644 --- a/pkg/commands/acl/create.go +++ b/pkg/commands/acl/create.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new ACL attached to the specified service version").Alias("add") @@ -40,7 +38,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -58,7 +56,6 @@ type CreateCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name cmd.OptionalString serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -70,7 +67,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, ErrLog: c.Globals.ErrLog, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/acl/delete.go b/pkg/commands/acl/delete.go index 01a7ffab9..90bb7a025 100644 --- a/pkg/commands/acl/delete.go +++ b/pkg/commands/acl/delete.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an ACL from the specified service version").Alias("remove") @@ -39,7 +37,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -57,7 +55,6 @@ type DeleteCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -68,7 +65,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/acl/describe.go b/pkg/commands/acl/describe.go index d6e2451cb..cfb7220a4 100644 --- a/pkg/commands/acl/describe.go +++ b/pkg/commands/acl/describe.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single ACL by name for the version and service").Alias("get") @@ -35,7 +34,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -68,7 +66,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/acl/list.go b/pkg/commands/acl/list.go index 7b186d1b6..071a3a5c7 100644 --- a/pkg/commands/acl/list.go +++ b/pkg/commands/acl/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List ACLs") @@ -35,7 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/acl/update.go b/pkg/commands/acl/update.go index 1a3acf6f8..3f7fc04a4 100644 --- a/pkg/commands/acl/update.go +++ b/pkg/commands/acl/update.go @@ -3,21 +3,20 @@ package acl import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update an ACL for a particular service and version") @@ -39,7 +38,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -57,7 +56,6 @@ type UpdateCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string newName string serviceName cmd.OptionalServiceNameID @@ -69,7 +67,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/aclentry/aclentry_test.go b/pkg/commands/aclentry/aclentry_test.go index 7be64aa8f..226850d06 100644 --- a/pkg/commands/aclentry/aclentry_test.go +++ b/pkg/commands/aclentry/aclentry_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -77,8 +78,8 @@ func TestACLEntryCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -133,8 +134,8 @@ func TestACLEntryDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -187,8 +188,8 @@ func TestACLEntryDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -336,8 +337,8 @@ func TestACLEntryList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -468,8 +469,8 @@ func TestACLEntryUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/aclentry/create.go b/pkg/commands/aclentry/create.go index 640c7b840..a75cf349e 100644 --- a/pkg/commands/aclentry/create.go +++ b/pkg/commands/aclentry/create.go @@ -3,20 +3,19 @@ package aclentry import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Add an ACL entry to an ACL").Alias("add") @@ -30,7 +29,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -51,7 +50,6 @@ type CreateCommand struct { aclID string comment cmd.OptionalString ip cmd.OptionalString - manifest manifest.Data negated cmd.OptionalBool serviceName cmd.OptionalServiceNameID subnet cmd.OptionalInt @@ -59,7 +57,7 @@ type CreateCommand struct { // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/aclentry/delete.go b/pkg/commands/aclentry/delete.go index 3b5a98f26..04f596a79 100644 --- a/pkg/commands/aclentry/delete.go +++ b/pkg/commands/aclentry/delete.go @@ -7,17 +7,15 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an ACL entry from a specified ACL").Alias("remove") @@ -29,7 +27,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -48,13 +46,12 @@ type DeleteCommand struct { aclID string id string - manifest manifest.Data serviceName cmd.OptionalServiceNameID } // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/aclentry/describe.go b/pkg/commands/aclentry/describe.go index 37796a606..cbb1d92bf 100644 --- a/pkg/commands/aclentry/describe.go +++ b/pkg/commands/aclentry/describe.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single ACL entry").Alias("get") @@ -30,7 +29,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -50,7 +49,6 @@ type DescribeCommand struct { aclID string id string - manifest manifest.Data serviceName cmd.OptionalServiceNameID } @@ -60,7 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/aclentry/list.go b/pkg/commands/aclentry/list.go index 115d41d43..55b3a634b 100644 --- a/pkg/commands/aclentry/list.go +++ b/pkg/commands/aclentry/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List ACLs") @@ -30,7 +29,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -55,7 +54,6 @@ type ListCommand struct { aclID string direction string - manifest manifest.Data page int perPage int serviceName cmd.OptionalServiceNameID @@ -68,7 +66,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/aclentry/update.go b/pkg/commands/aclentry/update.go index d5466c960..946512401 100644 --- a/pkg/commands/aclentry/update.go +++ b/pkg/commands/aclentry/update.go @@ -10,17 +10,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update an ACL entry for a specified ACL") @@ -36,7 +34,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -59,7 +57,6 @@ type UpdateCommand struct { file cmd.OptionalString id cmd.OptionalString ip cmd.OptionalString - manifest manifest.Data negated cmd.OptionalBool serviceName cmd.OptionalServiceNameID subnet cmd.OptionalInt @@ -67,7 +64,7 @@ type UpdateCommand struct { // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/authtoken/authtoken_test.go b/pkg/commands/authtoken/authtoken_test.go index a19a5760a..654922963 100644 --- a/pkg/commands/authtoken/authtoken_test.go +++ b/pkg/commands/authtoken/authtoken_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -70,8 +71,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -166,8 +167,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -205,8 +206,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -305,8 +306,8 @@ func TestList(t *testing.T) { }() } var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/authtoken/create.go b/pkg/commands/authtoken/create.go index 7c9992758..f677fc753 100644 --- a/pkg/commands/authtoken/create.go +++ b/pkg/commands/authtoken/create.go @@ -10,7 +10,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -19,12 +18,11 @@ import ( var Scopes = []string{"global", "purge_select", "purge_all", "global:read"} // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create an API token").Alias("add") @@ -55,7 +53,6 @@ type CreateCommand struct { cmd.Base expires time.Time - manifest manifest.Data name string password string scope []string diff --git a/pkg/commands/authtoken/delete.go b/pkg/commands/authtoken/delete.go index 7e700f114..1ccc3ecfe 100644 --- a/pkg/commands/authtoken/delete.go +++ b/pkg/commands/authtoken/delete.go @@ -11,17 +11,15 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Revoke an API token").Alias("remove") @@ -35,10 +33,9 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - current bool - file string - id string - manifest manifest.Data + current bool + file string + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/authtoken/describe.go b/pkg/commands/authtoken/describe.go index 28f0789a2..8ac545098 100644 --- a/pkg/commands/authtoken/describe.go +++ b/pkg/commands/authtoken/describe.go @@ -10,16 +10,14 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the current API token").Alias("get") @@ -31,8 +29,6 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) type DescribeCommand struct { cmd.Base cmd.JSONOutput - - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/authtoken/list.go b/pkg/commands/authtoken/list.go index 027a87ffb..4b871534f 100644 --- a/pkg/commands/authtoken/list.go +++ b/pkg/commands/authtoken/list.go @@ -10,17 +10,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List API tokens") @@ -40,7 +38,6 @@ type ListCommand struct { cmd.JSONOutput customerID cmd.OptionalCustomerID - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/backend/backend_test.go b/pkg/commands/backend/backend_test.go index 5e8d390f1..601f6df20 100644 --- a/pkg/commands/backend/backend_test.go +++ b/pkg/commands/backend/backend_test.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/app" fsterr "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -131,8 +132,8 @@ func TestBackendCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -215,8 +216,8 @@ func TestBackendList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -257,8 +258,8 @@ func TestBackendDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -301,8 +302,8 @@ func TestBackendUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -343,8 +344,8 @@ func TestBackendDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/backend/create.go b/pkg/commands/backend/create.go index 09749e918..d529dba12 100644 --- a/pkg/commands/backend/create.go +++ b/pkg/commands/backend/create.go @@ -9,14 +9,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // CreateCommand calls the Fastly API to create backends. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceVersion cmd.OptionalServiceVersion @@ -52,12 +50,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a backend on a Fastly service version").Alias("add") @@ -93,7 +90,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -121,7 +118,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/backend/delete.go b/pkg/commands/backend/delete.go index 50632dbdd..d45f096dc 100644 --- a/pkg/commands/backend/delete.go +++ b/pkg/commands/backend/delete.go @@ -3,18 +3,17 @@ package backend import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete backends. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteBackendInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a backend on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -66,7 +64,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/backend/describe.go b/pkg/commands/backend/describe.go index 9cecba7ef..a838ba786 100644 --- a/pkg/commands/backend/describe.go +++ b/pkg/commands/backend/describe.go @@ -4,11 +4,11 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a backend. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetBackendInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a backend on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/backend/list.go b/pkg/commands/backend/list.go index 0fafa4ed9..634573316 100644 --- a/pkg/commands/backend/list.go +++ b/pkg/commands/backend/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list backends. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListBackendsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List backends on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/backend/update.go b/pkg/commands/backend/update.go index 1c85b7c1d..1c4f3c484 100644 --- a/pkg/commands/backend/update.go +++ b/pkg/commands/backend/update.go @@ -8,14 +8,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // UpdateCommand calls the Fastly API to update backends. type UpdateCommand struct { cmd.Base - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion autoClone cmd.OptionalAutoClone @@ -50,12 +48,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a backend on a Fastly service version") @@ -91,7 +88,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -118,7 +115,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/app/commands.go b/pkg/commands/commands.go similarity index 75% rename from pkg/app/commands.go rename to pkg/commands/commands.go index 7b8657338..a83351476 100644 --- a/pkg/app/commands.go +++ b/pkg/commands/commands.go @@ -1,9 +1,8 @@ -package app +package commands import ( "github.com/fastly/kingpin" - "github.com/fastly/cli/pkg/auth" "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/acl" "github.com/fastly/cli/pkg/commands/aclentry" @@ -79,19 +78,14 @@ import ( "github.com/fastly/cli/pkg/commands/version" "github.com/fastly/cli/pkg/commands/whoami" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) -func defineCommands( +// Define constructs all the commands exposed by the CLI. +func Define( app *kingpin.Application, - g *global.Data, - m manifest.Data, - opener func(string) error, - authServer auth.Starter, - versioners Versioners, - factory APIClientFactory, + data *global.Data, ) []cmd.Command { - shellcompleteCmdRoot := shellcomplete.NewRootCommand(app, g) + shellcompleteCmdRoot := shellcomplete.NewRootCommand(app, data) // NOTE: The order commands are created are the order they appear in 'help'. // But because we need to pass the SSO command into the profile commands, it @@ -99,371 +93,371 @@ func defineCommands( // messes up the order of the commands in the `--help` output. So to make the // placement of the `sso` subcommand not look too odd we place it at the // beginning of the list of commands. - ssoCmdRoot := sso.NewRootCommand(app, g, opener, authServer) + ssoCmdRoot := sso.NewRootCommand(app, data) - aclCmdRoot := acl.NewRootCommand(app, g) - aclCreate := acl.NewCreateCommand(aclCmdRoot.CmdClause, g, m) - aclDelete := acl.NewDeleteCommand(aclCmdRoot.CmdClause, g, m) - aclDescribe := acl.NewDescribeCommand(aclCmdRoot.CmdClause, g, m) - aclList := acl.NewListCommand(aclCmdRoot.CmdClause, g, m) - aclUpdate := acl.NewUpdateCommand(aclCmdRoot.CmdClause, g, m) - aclEntryCmdRoot := aclentry.NewRootCommand(app, g) - aclEntryCreate := aclentry.NewCreateCommand(aclEntryCmdRoot.CmdClause, g, m) - aclEntryDelete := aclentry.NewDeleteCommand(aclEntryCmdRoot.CmdClause, g, m) - aclEntryDescribe := aclentry.NewDescribeCommand(aclEntryCmdRoot.CmdClause, g, m) - aclEntryList := aclentry.NewListCommand(aclEntryCmdRoot.CmdClause, g, m) - aclEntryUpdate := aclentry.NewUpdateCommand(aclEntryCmdRoot.CmdClause, g, m) - authtokenCmdRoot := authtoken.NewRootCommand(app, g) - authtokenCreate := authtoken.NewCreateCommand(authtokenCmdRoot.CmdClause, g, m) - authtokenDelete := authtoken.NewDeleteCommand(authtokenCmdRoot.CmdClause, g, m) - authtokenDescribe := authtoken.NewDescribeCommand(authtokenCmdRoot.CmdClause, g, m) - authtokenList := authtoken.NewListCommand(authtokenCmdRoot.CmdClause, g, m) - backendCmdRoot := backend.NewRootCommand(app, g) - backendCreate := backend.NewCreateCommand(backendCmdRoot.CmdClause, g, m) - backendDelete := backend.NewDeleteCommand(backendCmdRoot.CmdClause, g, m) - backendDescribe := backend.NewDescribeCommand(backendCmdRoot.CmdClause, g, m) - backendList := backend.NewListCommand(backendCmdRoot.CmdClause, g, m) - backendUpdate := backend.NewUpdateCommand(backendCmdRoot.CmdClause, g, m) - computeCmdRoot := compute.NewRootCommand(app, g) - computeBuild := compute.NewBuildCommand(computeCmdRoot.CmdClause, g, versioners.WasmTools) - computeDeploy := compute.NewDeployCommand(computeCmdRoot.CmdClause, g) - computeHashFiles := compute.NewHashFilesCommand(computeCmdRoot.CmdClause, g, computeBuild) - computeHashsum := compute.NewHashsumCommand(computeCmdRoot.CmdClause, g, computeBuild) - computeInit := compute.NewInitCommand(computeCmdRoot.CmdClause, g, m) - computeMetadata := compute.NewMetadataCommand(computeCmdRoot.CmdClause, g) - computePack := compute.NewPackCommand(computeCmdRoot.CmdClause, g, m) - computePublish := compute.NewPublishCommand(computeCmdRoot.CmdClause, g, computeBuild, computeDeploy) - computeServe := compute.NewServeCommand(computeCmdRoot.CmdClause, g, computeBuild, versioners.Viceroy) - computeUpdate := compute.NewUpdateCommand(computeCmdRoot.CmdClause, g, m) - computeValidate := compute.NewValidateCommand(computeCmdRoot.CmdClause, g) - configCmdRoot := config.NewRootCommand(app, g) - configstoreCmdRoot := configstore.NewRootCommand(app, g) - configstoreCreate := configstore.NewCreateCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreDelete := configstore.NewDeleteCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreDescribe := configstore.NewDescribeCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreList := configstore.NewListCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreListServices := configstore.NewListServicesCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreUpdate := configstore.NewUpdateCommand(configstoreCmdRoot.CmdClause, g, m) - configstoreentryCmdRoot := configstoreentry.NewRootCommand(app, g) - configstoreentryCreate := configstoreentry.NewCreateCommand(configstoreentryCmdRoot.CmdClause, g, m) - configstoreentryDelete := configstoreentry.NewDeleteCommand(configstoreentryCmdRoot.CmdClause, g, m) - configstoreentryDescribe := configstoreentry.NewDescribeCommand(configstoreentryCmdRoot.CmdClause, g, m) - configstoreentryList := configstoreentry.NewListCommand(configstoreentryCmdRoot.CmdClause, g, m) - configstoreentryUpdate := configstoreentry.NewUpdateCommand(configstoreentryCmdRoot.CmdClause, g, m) - dictionaryCmdRoot := dictionary.NewRootCommand(app, g) - dictionaryCreate := dictionary.NewCreateCommand(dictionaryCmdRoot.CmdClause, g, m) - dictionaryDelete := dictionary.NewDeleteCommand(dictionaryCmdRoot.CmdClause, g, m) - dictionaryDescribe := dictionary.NewDescribeCommand(dictionaryCmdRoot.CmdClause, g, m) - dictionaryEntryCmdRoot := dictionaryentry.NewRootCommand(app, g) - dictionaryEntryCreate := dictionaryentry.NewCreateCommand(dictionaryEntryCmdRoot.CmdClause, g, m) - dictionaryEntryDelete := dictionaryentry.NewDeleteCommand(dictionaryEntryCmdRoot.CmdClause, g, m) - dictionaryEntryDescribe := dictionaryentry.NewDescribeCommand(dictionaryEntryCmdRoot.CmdClause, g, m) - dictionaryEntryList := dictionaryentry.NewListCommand(dictionaryEntryCmdRoot.CmdClause, g, m) - dictionaryEntryUpdate := dictionaryentry.NewUpdateCommand(dictionaryEntryCmdRoot.CmdClause, g, m) - dictionaryList := dictionary.NewListCommand(dictionaryCmdRoot.CmdClause, g, m) - dictionaryUpdate := dictionary.NewUpdateCommand(dictionaryCmdRoot.CmdClause, g, m) - domainCmdRoot := domain.NewRootCommand(app, g) - domainCreate := domain.NewCreateCommand(domainCmdRoot.CmdClause, g, m) - domainDelete := domain.NewDeleteCommand(domainCmdRoot.CmdClause, g, m) - domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, g, m) - domainList := domain.NewListCommand(domainCmdRoot.CmdClause, g, m) - domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, g, m) - domainValidate := domain.NewValidateCommand(domainCmdRoot.CmdClause, g, m) - healthcheckCmdRoot := healthcheck.NewRootCommand(app, g) - healthcheckCreate := healthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, g, m) - healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, g, m) - healthcheckDescribe := healthcheck.NewDescribeCommand(healthcheckCmdRoot.CmdClause, g, m) - healthcheckList := healthcheck.NewListCommand(healthcheckCmdRoot.CmdClause, g, m) - healthcheckUpdate := healthcheck.NewUpdateCommand(healthcheckCmdRoot.CmdClause, g, m) - ipCmdRoot := ip.NewRootCommand(app, g) - kvstoreCmdRoot := kvstore.NewRootCommand(app, g) - kvstoreCreate := kvstore.NewCreateCommand(kvstoreCmdRoot.CmdClause, g, m) - kvstoreDelete := kvstore.NewDeleteCommand(kvstoreCmdRoot.CmdClause, g, m) - kvstoreDescribe := kvstore.NewDescribeCommand(kvstoreCmdRoot.CmdClause, g, m) - kvstoreList := kvstore.NewListCommand(kvstoreCmdRoot.CmdClause, g, m) - kvstoreentryCmdRoot := kvstoreentry.NewRootCommand(app, g) - kvstoreentryCreate := kvstoreentry.NewCreateCommand(kvstoreentryCmdRoot.CmdClause, g, m) - kvstoreentryDelete := kvstoreentry.NewDeleteCommand(kvstoreentryCmdRoot.CmdClause, g, m) - kvstoreentryDescribe := kvstoreentry.NewDescribeCommand(kvstoreentryCmdRoot.CmdClause, g, m) - kvstoreentryList := kvstoreentry.NewListCommand(kvstoreentryCmdRoot.CmdClause, g, m) - logtailCmdRoot := logtail.NewRootCommand(app, g, m) - loggingCmdRoot := logging.NewRootCommand(app, g) - loggingAzureblobCmdRoot := azureblob.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingAzureblobCreate := azureblob.NewCreateCommand(loggingAzureblobCmdRoot.CmdClause, g, m) - loggingAzureblobDelete := azureblob.NewDeleteCommand(loggingAzureblobCmdRoot.CmdClause, g, m) - loggingAzureblobDescribe := azureblob.NewDescribeCommand(loggingAzureblobCmdRoot.CmdClause, g, m) - loggingAzureblobList := azureblob.NewListCommand(loggingAzureblobCmdRoot.CmdClause, g, m) - loggingAzureblobUpdate := azureblob.NewUpdateCommand(loggingAzureblobCmdRoot.CmdClause, g, m) - loggingBigQueryCmdRoot := bigquery.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingBigQueryCreate := bigquery.NewCreateCommand(loggingBigQueryCmdRoot.CmdClause, g, m) - loggingBigQueryDelete := bigquery.NewDeleteCommand(loggingBigQueryCmdRoot.CmdClause, g, m) - loggingBigQueryDescribe := bigquery.NewDescribeCommand(loggingBigQueryCmdRoot.CmdClause, g, m) - loggingBigQueryList := bigquery.NewListCommand(loggingBigQueryCmdRoot.CmdClause, g, m) - loggingBigQueryUpdate := bigquery.NewUpdateCommand(loggingBigQueryCmdRoot.CmdClause, g, m) - loggingCloudfilesCmdRoot := cloudfiles.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingCloudfilesCreate := cloudfiles.NewCreateCommand(loggingCloudfilesCmdRoot.CmdClause, g, m) - loggingCloudfilesDelete := cloudfiles.NewDeleteCommand(loggingCloudfilesCmdRoot.CmdClause, g, m) - loggingCloudfilesDescribe := cloudfiles.NewDescribeCommand(loggingCloudfilesCmdRoot.CmdClause, g, m) - loggingCloudfilesList := cloudfiles.NewListCommand(loggingCloudfilesCmdRoot.CmdClause, g, m) - loggingCloudfilesUpdate := cloudfiles.NewUpdateCommand(loggingCloudfilesCmdRoot.CmdClause, g, m) - loggingDatadogCmdRoot := datadog.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingDatadogCreate := datadog.NewCreateCommand(loggingDatadogCmdRoot.CmdClause, g, m) - loggingDatadogDelete := datadog.NewDeleteCommand(loggingDatadogCmdRoot.CmdClause, g, m) - loggingDatadogDescribe := datadog.NewDescribeCommand(loggingDatadogCmdRoot.CmdClause, g, m) - loggingDatadogList := datadog.NewListCommand(loggingDatadogCmdRoot.CmdClause, g, m) - loggingDatadogUpdate := datadog.NewUpdateCommand(loggingDatadogCmdRoot.CmdClause, g, m) - loggingDigitaloceanCmdRoot := digitalocean.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingDigitaloceanCreate := digitalocean.NewCreateCommand(loggingDigitaloceanCmdRoot.CmdClause, g, m) - loggingDigitaloceanDelete := digitalocean.NewDeleteCommand(loggingDigitaloceanCmdRoot.CmdClause, g, m) - loggingDigitaloceanDescribe := digitalocean.NewDescribeCommand(loggingDigitaloceanCmdRoot.CmdClause, g, m) - loggingDigitaloceanList := digitalocean.NewListCommand(loggingDigitaloceanCmdRoot.CmdClause, g, m) - loggingDigitaloceanUpdate := digitalocean.NewUpdateCommand(loggingDigitaloceanCmdRoot.CmdClause, g, m) - loggingElasticsearchCmdRoot := elasticsearch.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingElasticsearchCreate := elasticsearch.NewCreateCommand(loggingElasticsearchCmdRoot.CmdClause, g, m) - loggingElasticsearchDelete := elasticsearch.NewDeleteCommand(loggingElasticsearchCmdRoot.CmdClause, g, m) - loggingElasticsearchDescribe := elasticsearch.NewDescribeCommand(loggingElasticsearchCmdRoot.CmdClause, g, m) - loggingElasticsearchList := elasticsearch.NewListCommand(loggingElasticsearchCmdRoot.CmdClause, g, m) - loggingElasticsearchUpdate := elasticsearch.NewUpdateCommand(loggingElasticsearchCmdRoot.CmdClause, g, m) - loggingFtpCmdRoot := ftp.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingFtpCreate := ftp.NewCreateCommand(loggingFtpCmdRoot.CmdClause, g, m) - loggingFtpDelete := ftp.NewDeleteCommand(loggingFtpCmdRoot.CmdClause, g, m) - loggingFtpDescribe := ftp.NewDescribeCommand(loggingFtpCmdRoot.CmdClause, g, m) - loggingFtpList := ftp.NewListCommand(loggingFtpCmdRoot.CmdClause, g, m) - loggingFtpUpdate := ftp.NewUpdateCommand(loggingFtpCmdRoot.CmdClause, g, m) - loggingGcsCmdRoot := gcs.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingGcsCreate := gcs.NewCreateCommand(loggingGcsCmdRoot.CmdClause, g, m) - loggingGcsDelete := gcs.NewDeleteCommand(loggingGcsCmdRoot.CmdClause, g, m) - loggingGcsDescribe := gcs.NewDescribeCommand(loggingGcsCmdRoot.CmdClause, g, m) - loggingGcsList := gcs.NewListCommand(loggingGcsCmdRoot.CmdClause, g, m) - loggingGcsUpdate := gcs.NewUpdateCommand(loggingGcsCmdRoot.CmdClause, g, m) - loggingGooglepubsubCmdRoot := googlepubsub.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingGooglepubsubCreate := googlepubsub.NewCreateCommand(loggingGooglepubsubCmdRoot.CmdClause, g, m) - loggingGooglepubsubDelete := googlepubsub.NewDeleteCommand(loggingGooglepubsubCmdRoot.CmdClause, g, m) - loggingGooglepubsubDescribe := googlepubsub.NewDescribeCommand(loggingGooglepubsubCmdRoot.CmdClause, g, m) - loggingGooglepubsubList := googlepubsub.NewListCommand(loggingGooglepubsubCmdRoot.CmdClause, g, m) - loggingGooglepubsubUpdate := googlepubsub.NewUpdateCommand(loggingGooglepubsubCmdRoot.CmdClause, g, m) - loggingHerokuCmdRoot := heroku.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingHerokuCreate := heroku.NewCreateCommand(loggingHerokuCmdRoot.CmdClause, g, m) - loggingHerokuDelete := heroku.NewDeleteCommand(loggingHerokuCmdRoot.CmdClause, g, m) - loggingHerokuDescribe := heroku.NewDescribeCommand(loggingHerokuCmdRoot.CmdClause, g, m) - loggingHerokuList := heroku.NewListCommand(loggingHerokuCmdRoot.CmdClause, g, m) - loggingHerokuUpdate := heroku.NewUpdateCommand(loggingHerokuCmdRoot.CmdClause, g, m) - loggingHoneycombCmdRoot := honeycomb.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingHoneycombCreate := honeycomb.NewCreateCommand(loggingHoneycombCmdRoot.CmdClause, g, m) - loggingHoneycombDelete := honeycomb.NewDeleteCommand(loggingHoneycombCmdRoot.CmdClause, g, m) - loggingHoneycombDescribe := honeycomb.NewDescribeCommand(loggingHoneycombCmdRoot.CmdClause, g, m) - loggingHoneycombList := honeycomb.NewListCommand(loggingHoneycombCmdRoot.CmdClause, g, m) - loggingHoneycombUpdate := honeycomb.NewUpdateCommand(loggingHoneycombCmdRoot.CmdClause, g, m) - loggingHTTPSCmdRoot := https.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingHTTPSCreate := https.NewCreateCommand(loggingHTTPSCmdRoot.CmdClause, g, m) - loggingHTTPSDelete := https.NewDeleteCommand(loggingHTTPSCmdRoot.CmdClause, g, m) - loggingHTTPSDescribe := https.NewDescribeCommand(loggingHTTPSCmdRoot.CmdClause, g, m) - loggingHTTPSList := https.NewListCommand(loggingHTTPSCmdRoot.CmdClause, g, m) - loggingHTTPSUpdate := https.NewUpdateCommand(loggingHTTPSCmdRoot.CmdClause, g, m) - loggingKafkaCmdRoot := kafka.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingKafkaCreate := kafka.NewCreateCommand(loggingKafkaCmdRoot.CmdClause, g, m) - loggingKafkaDelete := kafka.NewDeleteCommand(loggingKafkaCmdRoot.CmdClause, g, m) - loggingKafkaDescribe := kafka.NewDescribeCommand(loggingKafkaCmdRoot.CmdClause, g, m) - loggingKafkaList := kafka.NewListCommand(loggingKafkaCmdRoot.CmdClause, g, m) - loggingKafkaUpdate := kafka.NewUpdateCommand(loggingKafkaCmdRoot.CmdClause, g, m) - loggingKinesisCmdRoot := kinesis.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingKinesisCreate := kinesis.NewCreateCommand(loggingKinesisCmdRoot.CmdClause, g, m) - loggingKinesisDelete := kinesis.NewDeleteCommand(loggingKinesisCmdRoot.CmdClause, g, m) - loggingKinesisDescribe := kinesis.NewDescribeCommand(loggingKinesisCmdRoot.CmdClause, g, m) - loggingKinesisList := kinesis.NewListCommand(loggingKinesisCmdRoot.CmdClause, g, m) - loggingKinesisUpdate := kinesis.NewUpdateCommand(loggingKinesisCmdRoot.CmdClause, g, m) - loggingLogglyCmdRoot := loggly.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingLogglyCreate := loggly.NewCreateCommand(loggingLogglyCmdRoot.CmdClause, g, m) - loggingLogglyDelete := loggly.NewDeleteCommand(loggingLogglyCmdRoot.CmdClause, g, m) - loggingLogglyDescribe := loggly.NewDescribeCommand(loggingLogglyCmdRoot.CmdClause, g, m) - loggingLogglyList := loggly.NewListCommand(loggingLogglyCmdRoot.CmdClause, g, m) - loggingLogglyUpdate := loggly.NewUpdateCommand(loggingLogglyCmdRoot.CmdClause, g, m) - loggingLogshuttleCmdRoot := logshuttle.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingLogshuttleCreate := logshuttle.NewCreateCommand(loggingLogshuttleCmdRoot.CmdClause, g, m) - loggingLogshuttleDelete := logshuttle.NewDeleteCommand(loggingLogshuttleCmdRoot.CmdClause, g, m) - loggingLogshuttleDescribe := logshuttle.NewDescribeCommand(loggingLogshuttleCmdRoot.CmdClause, g, m) - loggingLogshuttleList := logshuttle.NewListCommand(loggingLogshuttleCmdRoot.CmdClause, g, m) - loggingLogshuttleUpdate := logshuttle.NewUpdateCommand(loggingLogshuttleCmdRoot.CmdClause, g, m) - loggingNewRelicCmdRoot := newrelic.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingNewRelicCreate := newrelic.NewCreateCommand(loggingNewRelicCmdRoot.CmdClause, g, m) - loggingNewRelicDelete := newrelic.NewDeleteCommand(loggingNewRelicCmdRoot.CmdClause, g, m) - loggingNewRelicDescribe := newrelic.NewDescribeCommand(loggingNewRelicCmdRoot.CmdClause, g, m) - loggingNewRelicList := newrelic.NewListCommand(loggingNewRelicCmdRoot.CmdClause, g, m) - loggingNewRelicUpdate := newrelic.NewUpdateCommand(loggingNewRelicCmdRoot.CmdClause, g, m) - loggingNewRelicOTLPCmdRoot := newrelicotlp.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingNewRelicOTLPCreate := newrelicotlp.NewCreateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m) - loggingNewRelicOTLPDelete := newrelicotlp.NewDeleteCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m) - loggingNewRelicOTLPDescribe := newrelicotlp.NewDescribeCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m) - loggingNewRelicOTLPList := newrelicotlp.NewListCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m) - loggingNewRelicOTLPUpdate := newrelicotlp.NewUpdateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m) - loggingOpenstackCmdRoot := openstack.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingOpenstackCreate := openstack.NewCreateCommand(loggingOpenstackCmdRoot.CmdClause, g, m) - loggingOpenstackDelete := openstack.NewDeleteCommand(loggingOpenstackCmdRoot.CmdClause, g, m) - loggingOpenstackDescribe := openstack.NewDescribeCommand(loggingOpenstackCmdRoot.CmdClause, g, m) - loggingOpenstackList := openstack.NewListCommand(loggingOpenstackCmdRoot.CmdClause, g, m) - loggingOpenstackUpdate := openstack.NewUpdateCommand(loggingOpenstackCmdRoot.CmdClause, g, m) - loggingPapertrailCmdRoot := papertrail.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingPapertrailCreate := papertrail.NewCreateCommand(loggingPapertrailCmdRoot.CmdClause, g, m) - loggingPapertrailDelete := papertrail.NewDeleteCommand(loggingPapertrailCmdRoot.CmdClause, g, m) - loggingPapertrailDescribe := papertrail.NewDescribeCommand(loggingPapertrailCmdRoot.CmdClause, g, m) - loggingPapertrailList := papertrail.NewListCommand(loggingPapertrailCmdRoot.CmdClause, g, m) - loggingPapertrailUpdate := papertrail.NewUpdateCommand(loggingPapertrailCmdRoot.CmdClause, g, m) - loggingS3CmdRoot := s3.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingS3Create := s3.NewCreateCommand(loggingS3CmdRoot.CmdClause, g, m) - loggingS3Delete := s3.NewDeleteCommand(loggingS3CmdRoot.CmdClause, g, m) - loggingS3Describe := s3.NewDescribeCommand(loggingS3CmdRoot.CmdClause, g, m) - loggingS3List := s3.NewListCommand(loggingS3CmdRoot.CmdClause, g, m) - loggingS3Update := s3.NewUpdateCommand(loggingS3CmdRoot.CmdClause, g, m) - loggingScalyrCmdRoot := scalyr.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingScalyrCreate := scalyr.NewCreateCommand(loggingScalyrCmdRoot.CmdClause, g, m) - loggingScalyrDelete := scalyr.NewDeleteCommand(loggingScalyrCmdRoot.CmdClause, g, m) - loggingScalyrDescribe := scalyr.NewDescribeCommand(loggingScalyrCmdRoot.CmdClause, g, m) - loggingScalyrList := scalyr.NewListCommand(loggingScalyrCmdRoot.CmdClause, g, m) - loggingScalyrUpdate := scalyr.NewUpdateCommand(loggingScalyrCmdRoot.CmdClause, g, m) - loggingSftpCmdRoot := sftp.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingSftpCreate := sftp.NewCreateCommand(loggingSftpCmdRoot.CmdClause, g, m) - loggingSftpDelete := sftp.NewDeleteCommand(loggingSftpCmdRoot.CmdClause, g, m) - loggingSftpDescribe := sftp.NewDescribeCommand(loggingSftpCmdRoot.CmdClause, g, m) - loggingSftpList := sftp.NewListCommand(loggingSftpCmdRoot.CmdClause, g, m) - loggingSftpUpdate := sftp.NewUpdateCommand(loggingSftpCmdRoot.CmdClause, g, m) - loggingSplunkCmdRoot := splunk.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingSplunkCreate := splunk.NewCreateCommand(loggingSplunkCmdRoot.CmdClause, g, m) - loggingSplunkDelete := splunk.NewDeleteCommand(loggingSplunkCmdRoot.CmdClause, g, m) - loggingSplunkDescribe := splunk.NewDescribeCommand(loggingSplunkCmdRoot.CmdClause, g, m) - loggingSplunkList := splunk.NewListCommand(loggingSplunkCmdRoot.CmdClause, g, m) - loggingSplunkUpdate := splunk.NewUpdateCommand(loggingSplunkCmdRoot.CmdClause, g, m) - loggingSumologicCmdRoot := sumologic.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingSumologicCreate := sumologic.NewCreateCommand(loggingSumologicCmdRoot.CmdClause, g, m) - loggingSumologicDelete := sumologic.NewDeleteCommand(loggingSumologicCmdRoot.CmdClause, g, m) - loggingSumologicDescribe := sumologic.NewDescribeCommand(loggingSumologicCmdRoot.CmdClause, g, m) - loggingSumologicList := sumologic.NewListCommand(loggingSumologicCmdRoot.CmdClause, g, m) - loggingSumologicUpdate := sumologic.NewUpdateCommand(loggingSumologicCmdRoot.CmdClause, g, m) - loggingSyslogCmdRoot := syslog.NewRootCommand(loggingCmdRoot.CmdClause, g) - loggingSyslogCreate := syslog.NewCreateCommand(loggingSyslogCmdRoot.CmdClause, g, m) - loggingSyslogDelete := syslog.NewDeleteCommand(loggingSyslogCmdRoot.CmdClause, g, m) - loggingSyslogDescribe := syslog.NewDescribeCommand(loggingSyslogCmdRoot.CmdClause, g, m) - loggingSyslogList := syslog.NewListCommand(loggingSyslogCmdRoot.CmdClause, g, m) - loggingSyslogUpdate := syslog.NewUpdateCommand(loggingSyslogCmdRoot.CmdClause, g, m) - popCmdRoot := pop.NewRootCommand(app, g) - productsCmdRoot := products.NewRootCommand(app, g, m) - profileCmdRoot := profile.NewRootCommand(app, g) - profileCreate := profile.NewCreateCommand(profileCmdRoot.CmdClause, profile.APIClientFactory(factory), g, ssoCmdRoot) - profileDelete := profile.NewDeleteCommand(profileCmdRoot.CmdClause, g) - profileList := profile.NewListCommand(profileCmdRoot.CmdClause, g) - profileSwitch := profile.NewSwitchCommand(profileCmdRoot.CmdClause, g) - profileToken := profile.NewTokenCommand(profileCmdRoot.CmdClause, g) - profileUpdate := profile.NewUpdateCommand(profileCmdRoot.CmdClause, profile.APIClientFactory(factory), g, ssoCmdRoot) - purgeCmdRoot := purge.NewRootCommand(app, g, m) - rateLimitCmdRoot := ratelimit.NewRootCommand(app, g) - rateLimitCreate := ratelimit.NewCreateCommand(rateLimitCmdRoot.CmdClause, g, m) - rateLimitDelete := ratelimit.NewDeleteCommand(rateLimitCmdRoot.CmdClause, g, m) - rateLimitDescribe := ratelimit.NewDescribeCommand(rateLimitCmdRoot.CmdClause, g, m) - rateLimitList := ratelimit.NewListCommand(rateLimitCmdRoot.CmdClause, g, m) - rateLimitUpdate := ratelimit.NewUpdateCommand(rateLimitCmdRoot.CmdClause, g, m) - resourcelinkCmdRoot := resourcelink.NewRootCommand(app, g) - resourcelinkCreate := resourcelink.NewCreateCommand(resourcelinkCmdRoot.CmdClause, g, m) - resourcelinkDelete := resourcelink.NewDeleteCommand(resourcelinkCmdRoot.CmdClause, g, m) - resourcelinkDescribe := resourcelink.NewDescribeCommand(resourcelinkCmdRoot.CmdClause, g, m) - resourcelinkList := resourcelink.NewListCommand(resourcelinkCmdRoot.CmdClause, g, m) - resourcelinkUpdate := resourcelink.NewUpdateCommand(resourcelinkCmdRoot.CmdClause, g, m) - secretstoreCmdRoot := secretstore.NewRootCommand(app, g) - secretstoreCreate := secretstore.NewCreateCommand(secretstoreCmdRoot.CmdClause, g, m) - secretstoreDescribe := secretstore.NewDescribeCommand(secretstoreCmdRoot.CmdClause, g, m) - secretstoreDelete := secretstore.NewDeleteCommand(secretstoreCmdRoot.CmdClause, g, m) - secretstoreList := secretstore.NewListCommand(secretstoreCmdRoot.CmdClause, g, m) - secretstoreentryCmdRoot := secretstoreentry.NewRootCommand(app, g) - secretstoreentryCreate := secretstoreentry.NewCreateCommand(secretstoreentryCmdRoot.CmdClause, g, m) - secretstoreentryDescribe := secretstoreentry.NewDescribeCommand(secretstoreentryCmdRoot.CmdClause, g, m) - secretstoreentryDelete := secretstoreentry.NewDeleteCommand(secretstoreentryCmdRoot.CmdClause, g, m) - secretstoreentryList := secretstoreentry.NewListCommand(secretstoreentryCmdRoot.CmdClause, g, m) - serviceCmdRoot := service.NewRootCommand(app, g) - serviceCreate := service.NewCreateCommand(serviceCmdRoot.CmdClause, g) - serviceDelete := service.NewDeleteCommand(serviceCmdRoot.CmdClause, g, m) - serviceDescribe := service.NewDescribeCommand(serviceCmdRoot.CmdClause, g, m) - serviceList := service.NewListCommand(serviceCmdRoot.CmdClause, g) - serviceSearch := service.NewSearchCommand(serviceCmdRoot.CmdClause, g, m) - serviceUpdate := service.NewUpdateCommand(serviceCmdRoot.CmdClause, g, m) - serviceauthCmdRoot := serviceauth.NewRootCommand(app, g) - serviceauthCreate := serviceauth.NewCreateCommand(serviceauthCmdRoot.CmdClause, g, m) - serviceauthDelete := serviceauth.NewDeleteCommand(serviceauthCmdRoot.CmdClause, g, m) - serviceauthDescribe := serviceauth.NewDescribeCommand(serviceauthCmdRoot.CmdClause, g, m) - serviceauthList := serviceauth.NewListCommand(serviceauthCmdRoot.CmdClause, g) - serviceauthUpdate := serviceauth.NewUpdateCommand(serviceauthCmdRoot.CmdClause, g, m) - serviceVersionCmdRoot := serviceversion.NewRootCommand(app, g) - serviceVersionActivate := serviceversion.NewActivateCommand(serviceVersionCmdRoot.CmdClause, g, m) - serviceVersionClone := serviceversion.NewCloneCommand(serviceVersionCmdRoot.CmdClause, g, m) - serviceVersionDeactivate := serviceversion.NewDeactivateCommand(serviceVersionCmdRoot.CmdClause, g, m) - serviceVersionList := serviceversion.NewListCommand(serviceVersionCmdRoot.CmdClause, g, m) - serviceVersionLock := serviceversion.NewLockCommand(serviceVersionCmdRoot.CmdClause, g, m) - serviceVersionUpdate := serviceversion.NewUpdateCommand(serviceVersionCmdRoot.CmdClause, g, m) - statsCmdRoot := stats.NewRootCommand(app, g) - statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, g, m) - statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, g, m) - statsRegions := stats.NewRegionsCommand(statsCmdRoot.CmdClause, g) - tlsConfigCmdRoot := tlsconfig.NewRootCommand(app, g) - tlsConfigDescribe := tlsconfig.NewDescribeCommand(tlsConfigCmdRoot.CmdClause, g, m) - tlsConfigList := tlsconfig.NewListCommand(tlsConfigCmdRoot.CmdClause, g, m) - tlsConfigUpdate := tlsconfig.NewUpdateCommand(tlsConfigCmdRoot.CmdClause, g, m) - tlsCustomCmdRoot := tlscustom.NewRootCommand(app, g) - tlsCustomActivationCmdRoot := tlscustomactivation.NewRootCommand(tlsCustomCmdRoot.CmdClause, g) - tlsCustomActivationCreate := tlscustomactivation.NewCreateCommand(tlsCustomActivationCmdRoot.CmdClause, g, m) - tlsCustomActivationDelete := tlscustomactivation.NewDeleteCommand(tlsCustomActivationCmdRoot.CmdClause, g, m) - tlsCustomActivationDescribe := tlscustomactivation.NewDescribeCommand(tlsCustomActivationCmdRoot.CmdClause, g, m) - tlsCustomActivationList := tlscustomactivation.NewListCommand(tlsCustomActivationCmdRoot.CmdClause, g, m) - tlsCustomActivationUpdate := tlscustomactivation.NewUpdateCommand(tlsCustomActivationCmdRoot.CmdClause, g, m) - tlsCustomCertificateCmdRoot := tlscustomcertificate.NewRootCommand(tlsCustomCmdRoot.CmdClause, g) - tlsCustomCertificateCreate := tlscustomcertificate.NewCreateCommand(tlsCustomCertificateCmdRoot.CmdClause, g, m) - tlsCustomCertificateDelete := tlscustomcertificate.NewDeleteCommand(tlsCustomCertificateCmdRoot.CmdClause, g, m) - tlsCustomCertificateDescribe := tlscustomcertificate.NewDescribeCommand(tlsCustomCertificateCmdRoot.CmdClause, g, m) - tlsCustomCertificateList := tlscustomcertificate.NewListCommand(tlsCustomCertificateCmdRoot.CmdClause, g, m) - tlsCustomCertificateUpdate := tlscustomcertificate.NewUpdateCommand(tlsCustomCertificateCmdRoot.CmdClause, g, m) - tlsCustomDomainCmdRoot := tlscustomdomain.NewRootCommand(tlsCustomCmdRoot.CmdClause, g) - tlsCustomDomainList := tlscustomdomain.NewListCommand(tlsCustomDomainCmdRoot.CmdClause, g, m) - tlsCustomPrivateKeyCmdRoot := tlscustomprivatekey.NewRootCommand(tlsCustomCmdRoot.CmdClause, g) - tlsCustomPrivateKeyCreate := tlscustomprivatekey.NewCreateCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, g, m) - tlsCustomPrivateKeyDelete := tlscustomprivatekey.NewDeleteCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, g, m) - tlsCustomPrivateKeyDescribe := tlscustomprivatekey.NewDescribeCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, g, m) - tlsCustomPrivateKeyList := tlscustomprivatekey.NewListCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, g, m) - tlsPlatformCmdRoot := tlsplatform.NewRootCommand(app, g) - tlsPlatformCreate := tlsplatform.NewCreateCommand(tlsPlatformCmdRoot.CmdClause, g, m) - tlsPlatformDelete := tlsplatform.NewDeleteCommand(tlsPlatformCmdRoot.CmdClause, g, m) - tlsPlatformDescribe := tlsplatform.NewDescribeCommand(tlsPlatformCmdRoot.CmdClause, g, m) - tlsPlatformList := tlsplatform.NewListCommand(tlsPlatformCmdRoot.CmdClause, g, m) - tlsPlatformUpdate := tlsplatform.NewUpdateCommand(tlsPlatformCmdRoot.CmdClause, g, m) - tlsSubscriptionCmdRoot := tlssubscription.NewRootCommand(app, g) - tlsSubscriptionCreate := tlssubscription.NewCreateCommand(tlsSubscriptionCmdRoot.CmdClause, g, m) - tlsSubscriptionDelete := tlssubscription.NewDeleteCommand(tlsSubscriptionCmdRoot.CmdClause, g, m) - tlsSubscriptionDescribe := tlssubscription.NewDescribeCommand(tlsSubscriptionCmdRoot.CmdClause, g, m) - tlsSubscriptionList := tlssubscription.NewListCommand(tlsSubscriptionCmdRoot.CmdClause, g, m) - tlsSubscriptionUpdate := tlssubscription.NewUpdateCommand(tlsSubscriptionCmdRoot.CmdClause, g, m) - updateRoot := update.NewRootCommand(app, g.ConfigPath, versioners.CLI, g) - userCmdRoot := user.NewRootCommand(app, g) - userCreate := user.NewCreateCommand(userCmdRoot.CmdClause, g, m) - userDelete := user.NewDeleteCommand(userCmdRoot.CmdClause, g, m) - userDescribe := user.NewDescribeCommand(userCmdRoot.CmdClause, g, m) - userList := user.NewListCommand(userCmdRoot.CmdClause, g, m) - userUpdate := user.NewUpdateCommand(userCmdRoot.CmdClause, g, m) - vclCmdRoot := vcl.NewRootCommand(app, g) - vclConditionCmdRoot := condition.NewRootCommand(vclCmdRoot.CmdClause, g) - vclConditionCreate := condition.NewCreateCommand(vclConditionCmdRoot.CmdClause, g, m) - vclConditionDelete := condition.NewDeleteCommand(vclConditionCmdRoot.CmdClause, g, m) - vclConditionDescribe := condition.NewDescribeCommand(vclConditionCmdRoot.CmdClause, g, m) - vclConditionList := condition.NewListCommand(vclConditionCmdRoot.CmdClause, g, m) - vclConditionUpdate := condition.NewUpdateCommand(vclConditionCmdRoot.CmdClause, g, m) - vclCustomCmdRoot := custom.NewRootCommand(vclCmdRoot.CmdClause, g) - vclCustomCreate := custom.NewCreateCommand(vclCustomCmdRoot.CmdClause, g, m) - vclCustomDelete := custom.NewDeleteCommand(vclCustomCmdRoot.CmdClause, g, m) - vclCustomDescribe := custom.NewDescribeCommand(vclCustomCmdRoot.CmdClause, g, m) - vclCustomList := custom.NewListCommand(vclCustomCmdRoot.CmdClause, g, m) - vclCustomUpdate := custom.NewUpdateCommand(vclCustomCmdRoot.CmdClause, g, m) - vclSnippetCmdRoot := snippet.NewRootCommand(vclCmdRoot.CmdClause, g) - vclSnippetCreate := snippet.NewCreateCommand(vclSnippetCmdRoot.CmdClause, g, m) - vclSnippetDelete := snippet.NewDeleteCommand(vclSnippetCmdRoot.CmdClause, g, m) - vclSnippetDescribe := snippet.NewDescribeCommand(vclSnippetCmdRoot.CmdClause, g, m) - vclSnippetList := snippet.NewListCommand(vclSnippetCmdRoot.CmdClause, g, m) - vclSnippetUpdate := snippet.NewUpdateCommand(vclSnippetCmdRoot.CmdClause, g, m) - versionCmdRoot := version.NewRootCommand(app, versioners.Viceroy) - whoamiCmdRoot := whoami.NewRootCommand(app, g) + aclCmdRoot := acl.NewRootCommand(app, data) + aclCreate := acl.NewCreateCommand(aclCmdRoot.CmdClause, data) + aclDelete := acl.NewDeleteCommand(aclCmdRoot.CmdClause, data) + aclDescribe := acl.NewDescribeCommand(aclCmdRoot.CmdClause, data) + aclList := acl.NewListCommand(aclCmdRoot.CmdClause, data) + aclUpdate := acl.NewUpdateCommand(aclCmdRoot.CmdClause, data) + aclEntryCmdRoot := aclentry.NewRootCommand(app, data) + aclEntryCreate := aclentry.NewCreateCommand(aclEntryCmdRoot.CmdClause, data) + aclEntryDelete := aclentry.NewDeleteCommand(aclEntryCmdRoot.CmdClause, data) + aclEntryDescribe := aclentry.NewDescribeCommand(aclEntryCmdRoot.CmdClause, data) + aclEntryList := aclentry.NewListCommand(aclEntryCmdRoot.CmdClause, data) + aclEntryUpdate := aclentry.NewUpdateCommand(aclEntryCmdRoot.CmdClause, data) + authtokenCmdRoot := authtoken.NewRootCommand(app, data) + authtokenCreate := authtoken.NewCreateCommand(authtokenCmdRoot.CmdClause, data) + authtokenDelete := authtoken.NewDeleteCommand(authtokenCmdRoot.CmdClause, data) + authtokenDescribe := authtoken.NewDescribeCommand(authtokenCmdRoot.CmdClause, data) + authtokenList := authtoken.NewListCommand(authtokenCmdRoot.CmdClause, data) + backendCmdRoot := backend.NewRootCommand(app, data) + backendCreate := backend.NewCreateCommand(backendCmdRoot.CmdClause, data) + backendDelete := backend.NewDeleteCommand(backendCmdRoot.CmdClause, data) + backendDescribe := backend.NewDescribeCommand(backendCmdRoot.CmdClause, data) + backendList := backend.NewListCommand(backendCmdRoot.CmdClause, data) + backendUpdate := backend.NewUpdateCommand(backendCmdRoot.CmdClause, data) + computeCmdRoot := compute.NewRootCommand(app, data) + computeBuild := compute.NewBuildCommand(computeCmdRoot.CmdClause, data) + computeDeploy := compute.NewDeployCommand(computeCmdRoot.CmdClause, data) + computeHashFiles := compute.NewHashFilesCommand(computeCmdRoot.CmdClause, data, computeBuild) + computeHashsum := compute.NewHashsumCommand(computeCmdRoot.CmdClause, data, computeBuild) + computeInit := compute.NewInitCommand(computeCmdRoot.CmdClause, data) + computeMetadata := compute.NewMetadataCommand(computeCmdRoot.CmdClause, data) + computePack := compute.NewPackCommand(computeCmdRoot.CmdClause, data) + computePublish := compute.NewPublishCommand(computeCmdRoot.CmdClause, data, computeBuild, computeDeploy) + computeServe := compute.NewServeCommand(computeCmdRoot.CmdClause, data, computeBuild) + computeUpdate := compute.NewUpdateCommand(computeCmdRoot.CmdClause, data) + computeValidate := compute.NewValidateCommand(computeCmdRoot.CmdClause, data) + configCmdRoot := config.NewRootCommand(app, data) + configstoreCmdRoot := configstore.NewRootCommand(app, data) + configstoreCreate := configstore.NewCreateCommand(configstoreCmdRoot.CmdClause, data) + configstoreDelete := configstore.NewDeleteCommand(configstoreCmdRoot.CmdClause, data) + configstoreDescribe := configstore.NewDescribeCommand(configstoreCmdRoot.CmdClause, data) + configstoreList := configstore.NewListCommand(configstoreCmdRoot.CmdClause, data) + configstoreListServices := configstore.NewListServicesCommand(configstoreCmdRoot.CmdClause, data) + configstoreUpdate := configstore.NewUpdateCommand(configstoreCmdRoot.CmdClause, data) + configstoreentryCmdRoot := configstoreentry.NewRootCommand(app, data) + configstoreentryCreate := configstoreentry.NewCreateCommand(configstoreentryCmdRoot.CmdClause, data) + configstoreentryDelete := configstoreentry.NewDeleteCommand(configstoreentryCmdRoot.CmdClause, data) + configstoreentryDescribe := configstoreentry.NewDescribeCommand(configstoreentryCmdRoot.CmdClause, data) + configstoreentryList := configstoreentry.NewListCommand(configstoreentryCmdRoot.CmdClause, data) + configstoreentryUpdate := configstoreentry.NewUpdateCommand(configstoreentryCmdRoot.CmdClause, data) + dictionaryCmdRoot := dictionary.NewRootCommand(app, data) + dictionaryCreate := dictionary.NewCreateCommand(dictionaryCmdRoot.CmdClause, data) + dictionaryDelete := dictionary.NewDeleteCommand(dictionaryCmdRoot.CmdClause, data) + dictionaryDescribe := dictionary.NewDescribeCommand(dictionaryCmdRoot.CmdClause, data) + dictionaryEntryCmdRoot := dictionaryentry.NewRootCommand(app, data) + dictionaryEntryCreate := dictionaryentry.NewCreateCommand(dictionaryEntryCmdRoot.CmdClause, data) + dictionaryEntryDelete := dictionaryentry.NewDeleteCommand(dictionaryEntryCmdRoot.CmdClause, data) + dictionaryEntryDescribe := dictionaryentry.NewDescribeCommand(dictionaryEntryCmdRoot.CmdClause, data) + dictionaryEntryList := dictionaryentry.NewListCommand(dictionaryEntryCmdRoot.CmdClause, data) + dictionaryEntryUpdate := dictionaryentry.NewUpdateCommand(dictionaryEntryCmdRoot.CmdClause, data) + dictionaryList := dictionary.NewListCommand(dictionaryCmdRoot.CmdClause, data) + dictionaryUpdate := dictionary.NewUpdateCommand(dictionaryCmdRoot.CmdClause, data) + domainCmdRoot := domain.NewRootCommand(app, data) + domainCreate := domain.NewCreateCommand(domainCmdRoot.CmdClause, data) + domainDelete := domain.NewDeleteCommand(domainCmdRoot.CmdClause, data) + domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, data) + domainList := domain.NewListCommand(domainCmdRoot.CmdClause, data) + domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, data) + domainValidate := domain.NewValidateCommand(domainCmdRoot.CmdClause, data) + healthcheckCmdRoot := healthcheck.NewRootCommand(app, data) + healthcheckCreate := healthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckDescribe := healthcheck.NewDescribeCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckList := healthcheck.NewListCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckUpdate := healthcheck.NewUpdateCommand(healthcheckCmdRoot.CmdClause, data) + ipCmdRoot := ip.NewRootCommand(app, data) + kvstoreCmdRoot := kvstore.NewRootCommand(app, data) + kvstoreCreate := kvstore.NewCreateCommand(kvstoreCmdRoot.CmdClause, data) + kvstoreDelete := kvstore.NewDeleteCommand(kvstoreCmdRoot.CmdClause, data) + kvstoreDescribe := kvstore.NewDescribeCommand(kvstoreCmdRoot.CmdClause, data) + kvstoreList := kvstore.NewListCommand(kvstoreCmdRoot.CmdClause, data) + kvstoreentryCmdRoot := kvstoreentry.NewRootCommand(app, data) + kvstoreentryCreate := kvstoreentry.NewCreateCommand(kvstoreentryCmdRoot.CmdClause, data) + kvstoreentryDelete := kvstoreentry.NewDeleteCommand(kvstoreentryCmdRoot.CmdClause, data) + kvstoreentryDescribe := kvstoreentry.NewDescribeCommand(kvstoreentryCmdRoot.CmdClause, data) + kvstoreentryList := kvstoreentry.NewListCommand(kvstoreentryCmdRoot.CmdClause, data) + logtailCmdRoot := logtail.NewRootCommand(app, data) + loggingCmdRoot := logging.NewRootCommand(app, data) + loggingAzureblobCmdRoot := azureblob.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingAzureblobCreate := azureblob.NewCreateCommand(loggingAzureblobCmdRoot.CmdClause, data) + loggingAzureblobDelete := azureblob.NewDeleteCommand(loggingAzureblobCmdRoot.CmdClause, data) + loggingAzureblobDescribe := azureblob.NewDescribeCommand(loggingAzureblobCmdRoot.CmdClause, data) + loggingAzureblobList := azureblob.NewListCommand(loggingAzureblobCmdRoot.CmdClause, data) + loggingAzureblobUpdate := azureblob.NewUpdateCommand(loggingAzureblobCmdRoot.CmdClause, data) + loggingBigQueryCmdRoot := bigquery.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingBigQueryCreate := bigquery.NewCreateCommand(loggingBigQueryCmdRoot.CmdClause, data) + loggingBigQueryDelete := bigquery.NewDeleteCommand(loggingBigQueryCmdRoot.CmdClause, data) + loggingBigQueryDescribe := bigquery.NewDescribeCommand(loggingBigQueryCmdRoot.CmdClause, data) + loggingBigQueryList := bigquery.NewListCommand(loggingBigQueryCmdRoot.CmdClause, data) + loggingBigQueryUpdate := bigquery.NewUpdateCommand(loggingBigQueryCmdRoot.CmdClause, data) + loggingCloudfilesCmdRoot := cloudfiles.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingCloudfilesCreate := cloudfiles.NewCreateCommand(loggingCloudfilesCmdRoot.CmdClause, data) + loggingCloudfilesDelete := cloudfiles.NewDeleteCommand(loggingCloudfilesCmdRoot.CmdClause, data) + loggingCloudfilesDescribe := cloudfiles.NewDescribeCommand(loggingCloudfilesCmdRoot.CmdClause, data) + loggingCloudfilesList := cloudfiles.NewListCommand(loggingCloudfilesCmdRoot.CmdClause, data) + loggingCloudfilesUpdate := cloudfiles.NewUpdateCommand(loggingCloudfilesCmdRoot.CmdClause, data) + loggingDatadogCmdRoot := datadog.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingDatadogCreate := datadog.NewCreateCommand(loggingDatadogCmdRoot.CmdClause, data) + loggingDatadogDelete := datadog.NewDeleteCommand(loggingDatadogCmdRoot.CmdClause, data) + loggingDatadogDescribe := datadog.NewDescribeCommand(loggingDatadogCmdRoot.CmdClause, data) + loggingDatadogList := datadog.NewListCommand(loggingDatadogCmdRoot.CmdClause, data) + loggingDatadogUpdate := datadog.NewUpdateCommand(loggingDatadogCmdRoot.CmdClause, data) + loggingDigitaloceanCmdRoot := digitalocean.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingDigitaloceanCreate := digitalocean.NewCreateCommand(loggingDigitaloceanCmdRoot.CmdClause, data) + loggingDigitaloceanDelete := digitalocean.NewDeleteCommand(loggingDigitaloceanCmdRoot.CmdClause, data) + loggingDigitaloceanDescribe := digitalocean.NewDescribeCommand(loggingDigitaloceanCmdRoot.CmdClause, data) + loggingDigitaloceanList := digitalocean.NewListCommand(loggingDigitaloceanCmdRoot.CmdClause, data) + loggingDigitaloceanUpdate := digitalocean.NewUpdateCommand(loggingDigitaloceanCmdRoot.CmdClause, data) + loggingElasticsearchCmdRoot := elasticsearch.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingElasticsearchCreate := elasticsearch.NewCreateCommand(loggingElasticsearchCmdRoot.CmdClause, data) + loggingElasticsearchDelete := elasticsearch.NewDeleteCommand(loggingElasticsearchCmdRoot.CmdClause, data) + loggingElasticsearchDescribe := elasticsearch.NewDescribeCommand(loggingElasticsearchCmdRoot.CmdClause, data) + loggingElasticsearchList := elasticsearch.NewListCommand(loggingElasticsearchCmdRoot.CmdClause, data) + loggingElasticsearchUpdate := elasticsearch.NewUpdateCommand(loggingElasticsearchCmdRoot.CmdClause, data) + loggingFtpCmdRoot := ftp.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingFtpCreate := ftp.NewCreateCommand(loggingFtpCmdRoot.CmdClause, data) + loggingFtpDelete := ftp.NewDeleteCommand(loggingFtpCmdRoot.CmdClause, data) + loggingFtpDescribe := ftp.NewDescribeCommand(loggingFtpCmdRoot.CmdClause, data) + loggingFtpList := ftp.NewListCommand(loggingFtpCmdRoot.CmdClause, data) + loggingFtpUpdate := ftp.NewUpdateCommand(loggingFtpCmdRoot.CmdClause, data) + loggingGcsCmdRoot := gcs.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingGcsCreate := gcs.NewCreateCommand(loggingGcsCmdRoot.CmdClause, data) + loggingGcsDelete := gcs.NewDeleteCommand(loggingGcsCmdRoot.CmdClause, data) + loggingGcsDescribe := gcs.NewDescribeCommand(loggingGcsCmdRoot.CmdClause, data) + loggingGcsList := gcs.NewListCommand(loggingGcsCmdRoot.CmdClause, data) + loggingGcsUpdate := gcs.NewUpdateCommand(loggingGcsCmdRoot.CmdClause, data) + loggingGooglepubsubCmdRoot := googlepubsub.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingGooglepubsubCreate := googlepubsub.NewCreateCommand(loggingGooglepubsubCmdRoot.CmdClause, data) + loggingGooglepubsubDelete := googlepubsub.NewDeleteCommand(loggingGooglepubsubCmdRoot.CmdClause, data) + loggingGooglepubsubDescribe := googlepubsub.NewDescribeCommand(loggingGooglepubsubCmdRoot.CmdClause, data) + loggingGooglepubsubList := googlepubsub.NewListCommand(loggingGooglepubsubCmdRoot.CmdClause, data) + loggingGooglepubsubUpdate := googlepubsub.NewUpdateCommand(loggingGooglepubsubCmdRoot.CmdClause, data) + loggingHerokuCmdRoot := heroku.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingHerokuCreate := heroku.NewCreateCommand(loggingHerokuCmdRoot.CmdClause, data) + loggingHerokuDelete := heroku.NewDeleteCommand(loggingHerokuCmdRoot.CmdClause, data) + loggingHerokuDescribe := heroku.NewDescribeCommand(loggingHerokuCmdRoot.CmdClause, data) + loggingHerokuList := heroku.NewListCommand(loggingHerokuCmdRoot.CmdClause, data) + loggingHerokuUpdate := heroku.NewUpdateCommand(loggingHerokuCmdRoot.CmdClause, data) + loggingHoneycombCmdRoot := honeycomb.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingHoneycombCreate := honeycomb.NewCreateCommand(loggingHoneycombCmdRoot.CmdClause, data) + loggingHoneycombDelete := honeycomb.NewDeleteCommand(loggingHoneycombCmdRoot.CmdClause, data) + loggingHoneycombDescribe := honeycomb.NewDescribeCommand(loggingHoneycombCmdRoot.CmdClause, data) + loggingHoneycombList := honeycomb.NewListCommand(loggingHoneycombCmdRoot.CmdClause, data) + loggingHoneycombUpdate := honeycomb.NewUpdateCommand(loggingHoneycombCmdRoot.CmdClause, data) + loggingHTTPSCmdRoot := https.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingHTTPSCreate := https.NewCreateCommand(loggingHTTPSCmdRoot.CmdClause, data) + loggingHTTPSDelete := https.NewDeleteCommand(loggingHTTPSCmdRoot.CmdClause, data) + loggingHTTPSDescribe := https.NewDescribeCommand(loggingHTTPSCmdRoot.CmdClause, data) + loggingHTTPSList := https.NewListCommand(loggingHTTPSCmdRoot.CmdClause, data) + loggingHTTPSUpdate := https.NewUpdateCommand(loggingHTTPSCmdRoot.CmdClause, data) + loggingKafkaCmdRoot := kafka.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingKafkaCreate := kafka.NewCreateCommand(loggingKafkaCmdRoot.CmdClause, data) + loggingKafkaDelete := kafka.NewDeleteCommand(loggingKafkaCmdRoot.CmdClause, data) + loggingKafkaDescribe := kafka.NewDescribeCommand(loggingKafkaCmdRoot.CmdClause, data) + loggingKafkaList := kafka.NewListCommand(loggingKafkaCmdRoot.CmdClause, data) + loggingKafkaUpdate := kafka.NewUpdateCommand(loggingKafkaCmdRoot.CmdClause, data) + loggingKinesisCmdRoot := kinesis.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingKinesisCreate := kinesis.NewCreateCommand(loggingKinesisCmdRoot.CmdClause, data) + loggingKinesisDelete := kinesis.NewDeleteCommand(loggingKinesisCmdRoot.CmdClause, data) + loggingKinesisDescribe := kinesis.NewDescribeCommand(loggingKinesisCmdRoot.CmdClause, data) + loggingKinesisList := kinesis.NewListCommand(loggingKinesisCmdRoot.CmdClause, data) + loggingKinesisUpdate := kinesis.NewUpdateCommand(loggingKinesisCmdRoot.CmdClause, data) + loggingLogglyCmdRoot := loggly.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingLogglyCreate := loggly.NewCreateCommand(loggingLogglyCmdRoot.CmdClause, data) + loggingLogglyDelete := loggly.NewDeleteCommand(loggingLogglyCmdRoot.CmdClause, data) + loggingLogglyDescribe := loggly.NewDescribeCommand(loggingLogglyCmdRoot.CmdClause, data) + loggingLogglyList := loggly.NewListCommand(loggingLogglyCmdRoot.CmdClause, data) + loggingLogglyUpdate := loggly.NewUpdateCommand(loggingLogglyCmdRoot.CmdClause, data) + loggingLogshuttleCmdRoot := logshuttle.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingLogshuttleCreate := logshuttle.NewCreateCommand(loggingLogshuttleCmdRoot.CmdClause, data) + loggingLogshuttleDelete := logshuttle.NewDeleteCommand(loggingLogshuttleCmdRoot.CmdClause, data) + loggingLogshuttleDescribe := logshuttle.NewDescribeCommand(loggingLogshuttleCmdRoot.CmdClause, data) + loggingLogshuttleList := logshuttle.NewListCommand(loggingLogshuttleCmdRoot.CmdClause, data) + loggingLogshuttleUpdate := logshuttle.NewUpdateCommand(loggingLogshuttleCmdRoot.CmdClause, data) + loggingNewRelicCmdRoot := newrelic.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingNewRelicCreate := newrelic.NewCreateCommand(loggingNewRelicCmdRoot.CmdClause, data) + loggingNewRelicDelete := newrelic.NewDeleteCommand(loggingNewRelicCmdRoot.CmdClause, data) + loggingNewRelicDescribe := newrelic.NewDescribeCommand(loggingNewRelicCmdRoot.CmdClause, data) + loggingNewRelicList := newrelic.NewListCommand(loggingNewRelicCmdRoot.CmdClause, data) + loggingNewRelicUpdate := newrelic.NewUpdateCommand(loggingNewRelicCmdRoot.CmdClause, data) + loggingNewRelicOTLPCmdRoot := newrelicotlp.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingNewRelicOTLPCreate := newrelicotlp.NewCreateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, data) + loggingNewRelicOTLPDelete := newrelicotlp.NewDeleteCommand(loggingNewRelicOTLPCmdRoot.CmdClause, data) + loggingNewRelicOTLPDescribe := newrelicotlp.NewDescribeCommand(loggingNewRelicOTLPCmdRoot.CmdClause, data) + loggingNewRelicOTLPList := newrelicotlp.NewListCommand(loggingNewRelicOTLPCmdRoot.CmdClause, data) + loggingNewRelicOTLPUpdate := newrelicotlp.NewUpdateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, data) + loggingOpenstackCmdRoot := openstack.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingOpenstackCreate := openstack.NewCreateCommand(loggingOpenstackCmdRoot.CmdClause, data) + loggingOpenstackDelete := openstack.NewDeleteCommand(loggingOpenstackCmdRoot.CmdClause, data) + loggingOpenstackDescribe := openstack.NewDescribeCommand(loggingOpenstackCmdRoot.CmdClause, data) + loggingOpenstackList := openstack.NewListCommand(loggingOpenstackCmdRoot.CmdClause, data) + loggingOpenstackUpdate := openstack.NewUpdateCommand(loggingOpenstackCmdRoot.CmdClause, data) + loggingPapertrailCmdRoot := papertrail.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingPapertrailCreate := papertrail.NewCreateCommand(loggingPapertrailCmdRoot.CmdClause, data) + loggingPapertrailDelete := papertrail.NewDeleteCommand(loggingPapertrailCmdRoot.CmdClause, data) + loggingPapertrailDescribe := papertrail.NewDescribeCommand(loggingPapertrailCmdRoot.CmdClause, data) + loggingPapertrailList := papertrail.NewListCommand(loggingPapertrailCmdRoot.CmdClause, data) + loggingPapertrailUpdate := papertrail.NewUpdateCommand(loggingPapertrailCmdRoot.CmdClause, data) + loggingS3CmdRoot := s3.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingS3Create := s3.NewCreateCommand(loggingS3CmdRoot.CmdClause, data) + loggingS3Delete := s3.NewDeleteCommand(loggingS3CmdRoot.CmdClause, data) + loggingS3Describe := s3.NewDescribeCommand(loggingS3CmdRoot.CmdClause, data) + loggingS3List := s3.NewListCommand(loggingS3CmdRoot.CmdClause, data) + loggingS3Update := s3.NewUpdateCommand(loggingS3CmdRoot.CmdClause, data) + loggingScalyrCmdRoot := scalyr.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingScalyrCreate := scalyr.NewCreateCommand(loggingScalyrCmdRoot.CmdClause, data) + loggingScalyrDelete := scalyr.NewDeleteCommand(loggingScalyrCmdRoot.CmdClause, data) + loggingScalyrDescribe := scalyr.NewDescribeCommand(loggingScalyrCmdRoot.CmdClause, data) + loggingScalyrList := scalyr.NewListCommand(loggingScalyrCmdRoot.CmdClause, data) + loggingScalyrUpdate := scalyr.NewUpdateCommand(loggingScalyrCmdRoot.CmdClause, data) + loggingSftpCmdRoot := sftp.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingSftpCreate := sftp.NewCreateCommand(loggingSftpCmdRoot.CmdClause, data) + loggingSftpDelete := sftp.NewDeleteCommand(loggingSftpCmdRoot.CmdClause, data) + loggingSftpDescribe := sftp.NewDescribeCommand(loggingSftpCmdRoot.CmdClause, data) + loggingSftpList := sftp.NewListCommand(loggingSftpCmdRoot.CmdClause, data) + loggingSftpUpdate := sftp.NewUpdateCommand(loggingSftpCmdRoot.CmdClause, data) + loggingSplunkCmdRoot := splunk.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingSplunkCreate := splunk.NewCreateCommand(loggingSplunkCmdRoot.CmdClause, data) + loggingSplunkDelete := splunk.NewDeleteCommand(loggingSplunkCmdRoot.CmdClause, data) + loggingSplunkDescribe := splunk.NewDescribeCommand(loggingSplunkCmdRoot.CmdClause, data) + loggingSplunkList := splunk.NewListCommand(loggingSplunkCmdRoot.CmdClause, data) + loggingSplunkUpdate := splunk.NewUpdateCommand(loggingSplunkCmdRoot.CmdClause, data) + loggingSumologicCmdRoot := sumologic.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingSumologicCreate := sumologic.NewCreateCommand(loggingSumologicCmdRoot.CmdClause, data) + loggingSumologicDelete := sumologic.NewDeleteCommand(loggingSumologicCmdRoot.CmdClause, data) + loggingSumologicDescribe := sumologic.NewDescribeCommand(loggingSumologicCmdRoot.CmdClause, data) + loggingSumologicList := sumologic.NewListCommand(loggingSumologicCmdRoot.CmdClause, data) + loggingSumologicUpdate := sumologic.NewUpdateCommand(loggingSumologicCmdRoot.CmdClause, data) + loggingSyslogCmdRoot := syslog.NewRootCommand(loggingCmdRoot.CmdClause, data) + loggingSyslogCreate := syslog.NewCreateCommand(loggingSyslogCmdRoot.CmdClause, data) + loggingSyslogDelete := syslog.NewDeleteCommand(loggingSyslogCmdRoot.CmdClause, data) + loggingSyslogDescribe := syslog.NewDescribeCommand(loggingSyslogCmdRoot.CmdClause, data) + loggingSyslogList := syslog.NewListCommand(loggingSyslogCmdRoot.CmdClause, data) + loggingSyslogUpdate := syslog.NewUpdateCommand(loggingSyslogCmdRoot.CmdClause, data) + popCmdRoot := pop.NewRootCommand(app, data) + productsCmdRoot := products.NewRootCommand(app, data) + profileCmdRoot := profile.NewRootCommand(app, data) + profileCreate := profile.NewCreateCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot) + profileDelete := profile.NewDeleteCommand(profileCmdRoot.CmdClause, data) + profileList := profile.NewListCommand(profileCmdRoot.CmdClause, data) + profileSwitch := profile.NewSwitchCommand(profileCmdRoot.CmdClause, data) + profileToken := profile.NewTokenCommand(profileCmdRoot.CmdClause, data) + profileUpdate := profile.NewUpdateCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot) + purgeCmdRoot := purge.NewRootCommand(app, data) + rateLimitCmdRoot := ratelimit.NewRootCommand(app, data) + rateLimitCreate := ratelimit.NewCreateCommand(rateLimitCmdRoot.CmdClause, data) + rateLimitDelete := ratelimit.NewDeleteCommand(rateLimitCmdRoot.CmdClause, data) + rateLimitDescribe := ratelimit.NewDescribeCommand(rateLimitCmdRoot.CmdClause, data) + rateLimitList := ratelimit.NewListCommand(rateLimitCmdRoot.CmdClause, data) + rateLimitUpdate := ratelimit.NewUpdateCommand(rateLimitCmdRoot.CmdClause, data) + resourcelinkCmdRoot := resourcelink.NewRootCommand(app, data) + resourcelinkCreate := resourcelink.NewCreateCommand(resourcelinkCmdRoot.CmdClause, data) + resourcelinkDelete := resourcelink.NewDeleteCommand(resourcelinkCmdRoot.CmdClause, data) + resourcelinkDescribe := resourcelink.NewDescribeCommand(resourcelinkCmdRoot.CmdClause, data) + resourcelinkList := resourcelink.NewListCommand(resourcelinkCmdRoot.CmdClause, data) + resourcelinkUpdate := resourcelink.NewUpdateCommand(resourcelinkCmdRoot.CmdClause, data) + secretstoreCmdRoot := secretstore.NewRootCommand(app, data) + secretstoreCreate := secretstore.NewCreateCommand(secretstoreCmdRoot.CmdClause, data) + secretstoreDescribe := secretstore.NewDescribeCommand(secretstoreCmdRoot.CmdClause, data) + secretstoreDelete := secretstore.NewDeleteCommand(secretstoreCmdRoot.CmdClause, data) + secretstoreList := secretstore.NewListCommand(secretstoreCmdRoot.CmdClause, data) + secretstoreentryCmdRoot := secretstoreentry.NewRootCommand(app, data) + secretstoreentryCreate := secretstoreentry.NewCreateCommand(secretstoreentryCmdRoot.CmdClause, data) + secretstoreentryDescribe := secretstoreentry.NewDescribeCommand(secretstoreentryCmdRoot.CmdClause, data) + secretstoreentryDelete := secretstoreentry.NewDeleteCommand(secretstoreentryCmdRoot.CmdClause, data) + secretstoreentryList := secretstoreentry.NewListCommand(secretstoreentryCmdRoot.CmdClause, data) + serviceCmdRoot := service.NewRootCommand(app, data) + serviceCreate := service.NewCreateCommand(serviceCmdRoot.CmdClause, data) + serviceDelete := service.NewDeleteCommand(serviceCmdRoot.CmdClause, data) + serviceDescribe := service.NewDescribeCommand(serviceCmdRoot.CmdClause, data) + serviceList := service.NewListCommand(serviceCmdRoot.CmdClause, data) + serviceSearch := service.NewSearchCommand(serviceCmdRoot.CmdClause, data) + serviceUpdate := service.NewUpdateCommand(serviceCmdRoot.CmdClause, data) + serviceauthCmdRoot := serviceauth.NewRootCommand(app, data) + serviceauthCreate := serviceauth.NewCreateCommand(serviceauthCmdRoot.CmdClause, data) + serviceauthDelete := serviceauth.NewDeleteCommand(serviceauthCmdRoot.CmdClause, data) + serviceauthDescribe := serviceauth.NewDescribeCommand(serviceauthCmdRoot.CmdClause, data) + serviceauthList := serviceauth.NewListCommand(serviceauthCmdRoot.CmdClause, data) + serviceauthUpdate := serviceauth.NewUpdateCommand(serviceauthCmdRoot.CmdClause, data) + serviceVersionCmdRoot := serviceversion.NewRootCommand(app, data) + serviceVersionActivate := serviceversion.NewActivateCommand(serviceVersionCmdRoot.CmdClause, data) + serviceVersionClone := serviceversion.NewCloneCommand(serviceVersionCmdRoot.CmdClause, data) + serviceVersionDeactivate := serviceversion.NewDeactivateCommand(serviceVersionCmdRoot.CmdClause, data) + serviceVersionList := serviceversion.NewListCommand(serviceVersionCmdRoot.CmdClause, data) + serviceVersionLock := serviceversion.NewLockCommand(serviceVersionCmdRoot.CmdClause, data) + serviceVersionUpdate := serviceversion.NewUpdateCommand(serviceVersionCmdRoot.CmdClause, data) + statsCmdRoot := stats.NewRootCommand(app, data) + statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, data) + statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, data) + statsRegions := stats.NewRegionsCommand(statsCmdRoot.CmdClause, data) + tlsConfigCmdRoot := tlsconfig.NewRootCommand(app, data) + tlsConfigDescribe := tlsconfig.NewDescribeCommand(tlsConfigCmdRoot.CmdClause, data) + tlsConfigList := tlsconfig.NewListCommand(tlsConfigCmdRoot.CmdClause, data) + tlsConfigUpdate := tlsconfig.NewUpdateCommand(tlsConfigCmdRoot.CmdClause, data) + tlsCustomCmdRoot := tlscustom.NewRootCommand(app, data) + tlsCustomActivationCmdRoot := tlscustomactivation.NewRootCommand(tlsCustomCmdRoot.CmdClause, data) + tlsCustomActivationCreate := tlscustomactivation.NewCreateCommand(tlsCustomActivationCmdRoot.CmdClause, data) + tlsCustomActivationDelete := tlscustomactivation.NewDeleteCommand(tlsCustomActivationCmdRoot.CmdClause, data) + tlsCustomActivationDescribe := tlscustomactivation.NewDescribeCommand(tlsCustomActivationCmdRoot.CmdClause, data) + tlsCustomActivationList := tlscustomactivation.NewListCommand(tlsCustomActivationCmdRoot.CmdClause, data) + tlsCustomActivationUpdate := tlscustomactivation.NewUpdateCommand(tlsCustomActivationCmdRoot.CmdClause, data) + tlsCustomCertificateCmdRoot := tlscustomcertificate.NewRootCommand(tlsCustomCmdRoot.CmdClause, data) + tlsCustomCertificateCreate := tlscustomcertificate.NewCreateCommand(tlsCustomCertificateCmdRoot.CmdClause, data) + tlsCustomCertificateDelete := tlscustomcertificate.NewDeleteCommand(tlsCustomCertificateCmdRoot.CmdClause, data) + tlsCustomCertificateDescribe := tlscustomcertificate.NewDescribeCommand(tlsCustomCertificateCmdRoot.CmdClause, data) + tlsCustomCertificateList := tlscustomcertificate.NewListCommand(tlsCustomCertificateCmdRoot.CmdClause, data) + tlsCustomCertificateUpdate := tlscustomcertificate.NewUpdateCommand(tlsCustomCertificateCmdRoot.CmdClause, data) + tlsCustomDomainCmdRoot := tlscustomdomain.NewRootCommand(tlsCustomCmdRoot.CmdClause, data) + tlsCustomDomainList := tlscustomdomain.NewListCommand(tlsCustomDomainCmdRoot.CmdClause, data) + tlsCustomPrivateKeyCmdRoot := tlscustomprivatekey.NewRootCommand(tlsCustomCmdRoot.CmdClause, data) + tlsCustomPrivateKeyCreate := tlscustomprivatekey.NewCreateCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, data) + tlsCustomPrivateKeyDelete := tlscustomprivatekey.NewDeleteCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, data) + tlsCustomPrivateKeyDescribe := tlscustomprivatekey.NewDescribeCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, data) + tlsCustomPrivateKeyList := tlscustomprivatekey.NewListCommand(tlsCustomPrivateKeyCmdRoot.CmdClause, data) + tlsPlatformCmdRoot := tlsplatform.NewRootCommand(app, data) + tlsPlatformCreate := tlsplatform.NewCreateCommand(tlsPlatformCmdRoot.CmdClause, data) + tlsPlatformDelete := tlsplatform.NewDeleteCommand(tlsPlatformCmdRoot.CmdClause, data) + tlsPlatformDescribe := tlsplatform.NewDescribeCommand(tlsPlatformCmdRoot.CmdClause, data) + tlsPlatformList := tlsplatform.NewListCommand(tlsPlatformCmdRoot.CmdClause, data) + tlsPlatformUpdate := tlsplatform.NewUpdateCommand(tlsPlatformCmdRoot.CmdClause, data) + tlsSubscriptionCmdRoot := tlssubscription.NewRootCommand(app, data) + tlsSubscriptionCreate := tlssubscription.NewCreateCommand(tlsSubscriptionCmdRoot.CmdClause, data) + tlsSubscriptionDelete := tlssubscription.NewDeleteCommand(tlsSubscriptionCmdRoot.CmdClause, data) + tlsSubscriptionDescribe := tlssubscription.NewDescribeCommand(tlsSubscriptionCmdRoot.CmdClause, data) + tlsSubscriptionList := tlssubscription.NewListCommand(tlsSubscriptionCmdRoot.CmdClause, data) + tlsSubscriptionUpdate := tlssubscription.NewUpdateCommand(tlsSubscriptionCmdRoot.CmdClause, data) + updateRoot := update.NewRootCommand(app, data) + userCmdRoot := user.NewRootCommand(app, data) + userCreate := user.NewCreateCommand(userCmdRoot.CmdClause, data) + userDelete := user.NewDeleteCommand(userCmdRoot.CmdClause, data) + userDescribe := user.NewDescribeCommand(userCmdRoot.CmdClause, data) + userList := user.NewListCommand(userCmdRoot.CmdClause, data) + userUpdate := user.NewUpdateCommand(userCmdRoot.CmdClause, data) + vclCmdRoot := vcl.NewRootCommand(app, data) + vclConditionCmdRoot := condition.NewRootCommand(vclCmdRoot.CmdClause, data) + vclConditionCreate := condition.NewCreateCommand(vclConditionCmdRoot.CmdClause, data) + vclConditionDelete := condition.NewDeleteCommand(vclConditionCmdRoot.CmdClause, data) + vclConditionDescribe := condition.NewDescribeCommand(vclConditionCmdRoot.CmdClause, data) + vclConditionList := condition.NewListCommand(vclConditionCmdRoot.CmdClause, data) + vclConditionUpdate := condition.NewUpdateCommand(vclConditionCmdRoot.CmdClause, data) + vclCustomCmdRoot := custom.NewRootCommand(vclCmdRoot.CmdClause, data) + vclCustomCreate := custom.NewCreateCommand(vclCustomCmdRoot.CmdClause, data) + vclCustomDelete := custom.NewDeleteCommand(vclCustomCmdRoot.CmdClause, data) + vclCustomDescribe := custom.NewDescribeCommand(vclCustomCmdRoot.CmdClause, data) + vclCustomList := custom.NewListCommand(vclCustomCmdRoot.CmdClause, data) + vclCustomUpdate := custom.NewUpdateCommand(vclCustomCmdRoot.CmdClause, data) + vclSnippetCmdRoot := snippet.NewRootCommand(vclCmdRoot.CmdClause, data) + vclSnippetCreate := snippet.NewCreateCommand(vclSnippetCmdRoot.CmdClause, data) + vclSnippetDelete := snippet.NewDeleteCommand(vclSnippetCmdRoot.CmdClause, data) + vclSnippetDescribe := snippet.NewDescribeCommand(vclSnippetCmdRoot.CmdClause, data) + vclSnippetList := snippet.NewListCommand(vclSnippetCmdRoot.CmdClause, data) + vclSnippetUpdate := snippet.NewUpdateCommand(vclSnippetCmdRoot.CmdClause, data) + versionCmdRoot := version.NewRootCommand(app, data) + whoamiCmdRoot := whoami.NewRootCommand(app, data) return []cmd.Command{ shellcompleteCmdRoot, diff --git a/pkg/commands/compute/build.go b/pkg/commands/compute/build.go index 4a4033324..f0684babc 100644 --- a/pkg/commands/compute/build.go +++ b/pkg/commands/compute/build.go @@ -57,7 +57,6 @@ type Flags struct { // BuildCommand produces a deployable artifact from files on the local disk. type BuildCommand struct { cmd.Base - wasmtoolsVersioner github.AssetVersioner // NOTE: Composite commands require these build flags to be public. // e.g. serve, publish, hashsum, hash-files @@ -69,11 +68,9 @@ type BuildCommand struct { } // NewBuildCommand returns a usable command registered under the parent. -func NewBuildCommand(parent cmd.Registerer, g *global.Data, wasmtoolsVersioner github.AssetVersioner) *BuildCommand { +func NewBuildCommand(parent cmd.Registerer, g *global.Data) *BuildCommand { var c BuildCommand c.Globals = g - c.wasmtoolsVersioner = wasmtoolsVersioner - c.CmdClause = parent.Command("build", "Build a Compute package locally") // NOTE: when updating these flags, be sure to update the composite commands: @@ -157,7 +154,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) { return err } - wasmtools, wasmtoolsErr := GetWasmTools(spinner, out, c.wasmtoolsVersioner, c.Globals) + wasmtools, wasmtoolsErr := GetWasmTools(spinner, out, c.Globals.Versioners.WasmTools, c.Globals) var pkgName string err = spinner.Process("Identifying package name", func(_ *text.SpinnerWrapper) error { diff --git a/pkg/commands/compute/build_test.go b/pkg/commands/compute/build_test.go index 11b59dc3b..8f4d70864 100644 --- a/pkg/commands/compute/build_test.go +++ b/pkg/commands/compute/build_test.go @@ -12,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/compute" "github.com/fastly/cli/pkg/config" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" @@ -217,12 +218,12 @@ func TestBuildRust(t *testing.T) { }() var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) if testcase.applicationConfig != nil { - opts.ConfigFile = *testcase.applicationConfig + opts.Config = *testcase.applicationConfig } - opts.Versioners = app.Versioners{ + opts.Versioners = global.Versioners{ WasmTools: mock.AssetVersioner{ AssetVersion: "1.2.3", BinaryFilename: wasmtoolsBinName, @@ -410,12 +411,12 @@ func TestBuildGo(t *testing.T) { }() var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) if testcase.applicationConfig != nil { - opts.ConfigFile = *testcase.applicationConfig + opts.Config = *testcase.applicationConfig } - opts.Versioners = app.Versioners{ + opts.Versioners = global.Versioners{ WasmTools: mock.AssetVersioner{ AssetVersion: "1.2.3", BinaryFilename: wasmtoolsBinName, @@ -460,7 +461,7 @@ func TestBuildJavaScript(t *testing.T) { wantRemediationError string wantOutput []string npmInstall bool - versioners *app.Versioners + versioners *global.Versioners }{ { name: "no fastly.toml manifest", @@ -608,9 +609,9 @@ func TestBuildJavaScript(t *testing.T) { } var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) - opts.Versioners = app.Versioners{ + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) + opts.Versioners = global.Versioners{ WasmTools: mock.AssetVersioner{ AssetVersion: "1.2.3", BinaryFilename: wasmtoolsBinName, @@ -803,9 +804,9 @@ func TestBuildAssemblyScript(t *testing.T) { } var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) - opts.Versioners = app.Versioners{ + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) + opts.Versioners = global.Versioners{ WasmTools: mock.AssetVersioner{ AssetVersion: "1.2.3", BinaryFilename: wasmtoolsBinName, @@ -1015,10 +1016,10 @@ func TestBuildOther(t *testing.T) { } var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) - opts.Stdin = strings.NewReader(testcase.stdin) // NOTE: build only has one prompt when dealing with a custom build - opts.Versioners = app.Versioners{ + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) + opts.Input = strings.NewReader(testcase.stdin) // NOTE: build only has one prompt when dealing with a custom build + opts.Versioners = global.Versioners{ WasmTools: mock.AssetVersioner{ AssetVersion: "1.2.3", BinaryFilename: wasmtoolsBinName, diff --git a/pkg/commands/compute/compute_test.go b/pkg/commands/compute/compute_test.go index 2a6883ea8..4c77357e5 100644 --- a/pkg/commands/compute/compute_test.go +++ b/pkg/commands/compute/compute_test.go @@ -10,8 +10,8 @@ import ( "github.com/mholt/archiver/v3" "github.com/fastly/cli/pkg/commands/compute" - "github.com/fastly/cli/pkg/github" "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/testutil" ) @@ -20,10 +20,11 @@ import ( // `compute build` and `compute deploy` commands from which publish is composed. func TestFlagDivergencePublish(t *testing.T) { var g global.Data + g.Manifest = &manifest.Data{} acmd := kingpin.New("foo", "bar") rcmd := compute.NewRootCommand(acmd, &g) - bcmd := compute.NewBuildCommand(rcmd.CmdClause, &g, nil) + bcmd := compute.NewBuildCommand(rcmd.CmdClause, &g) dcmd := compute.NewDeployCommand(rcmd.CmdClause, &g) pcmd := compute.NewPublishCommand(rcmd.CmdClause, &g, bcmd, dcmd) @@ -68,16 +69,11 @@ func TestFlagDivergencePublish(t *testing.T) { // `compute build` command as `compute serve` delegates to build. func TestFlagDivergenceServe(t *testing.T) { var cfg global.Data - versioner := github.New(github.Opts{ - Org: "fastly", - Repo: "viceroy", - Binary: "viceroy", - }) acmd := kingpin.New("foo", "bar") rcmd := compute.NewRootCommand(acmd, &cfg) - bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg, nil) - scmd := compute.NewServeCommand(rcmd.CmdClause, &cfg, bcmd, versioner) + bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg) + scmd := compute.NewServeCommand(rcmd.CmdClause, &cfg, bcmd) buildFlags := getFlags(bcmd.CmdClause) serveFlags := getFlags(scmd.CmdClause) @@ -135,7 +131,7 @@ func TestFlagDivergenceHashSum(t *testing.T) { acmd := kingpin.New("foo", "bar") rcmd := compute.NewRootCommand(acmd, &cfg) - bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg, nil) + bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg) hcmd := compute.NewHashsumCommand(rcmd.CmdClause, &cfg, bcmd) buildFlags := getFlags(bcmd.CmdClause) @@ -186,7 +182,7 @@ func TestFlagDivergenceHashFiles(t *testing.T) { acmd := kingpin.New("foo", "bar") rcmd := compute.NewRootCommand(acmd, &cfg) - bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg, nil) + bcmd := compute.NewBuildCommand(rcmd.CmdClause, &cfg) hcmd := compute.NewHashFilesCommand(rcmd.CmdClause, &cfg, bcmd) buildFlags := getFlags(bcmd.CmdClause) diff --git a/pkg/commands/compute/deploy.go b/pkg/commands/compute/deploy.go index 2546e5ca9..811978738 100644 --- a/pkg/commands/compute/deploy.go +++ b/pkg/commands/compute/deploy.go @@ -147,7 +147,7 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) { } // Otherwise, we'll attempt to read the manifest from within the given // package archive. - if err := readManifestFromPackageArchive(&c.Globals.Manifest, c.PackagePath, manifestFilename); err != nil { + if err := readManifestFromPackageArchive(c.Globals.Manifest, c.PackagePath, manifestFilename); err != nil { return err } if c.Globals.Verbose() { @@ -358,7 +358,7 @@ func (c *DeployCommand) Setup(out io.Writer) (fnActivateTrial Activator, service // IMPORTANT: We don't handle the error when looking up the Service ID. // This is because later in the Exec() flow we might create a 'new' service. - serviceID, source, flag, err := cmd.ServiceID(c.ServiceName, c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.ServiceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err == nil && c.Globals.Verbose() { cmd.DisplayServiceID(serviceID, flag, source, out) } diff --git a/pkg/commands/compute/deploy_test.go b/pkg/commands/compute/deploy_test.go index 448410327..f098c7d49 100644 --- a/pkg/commands/compute/deploy_test.go +++ b/pkg/commands/compute/deploy_test.go @@ -17,6 +17,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/compute" "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" @@ -2153,7 +2154,7 @@ func TestDeploy(t *testing.T) { } var stdout threadsafe.Buffer - opts := testutil.NewRunOpts(testcase.args, &stdout) + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) if testcase.httpClientRes != nil || testcase.httpClientErr != nil { @@ -2172,7 +2173,7 @@ func TestDeploy(t *testing.T) { // To handle multiple prompt input from the user we need to do some // coordination around io pipes to mimic the required user behaviour. stdin, prompt := io.Pipe() - opts.Stdin = stdin + opts.Input = stdin // Wait for user input and write it to the prompt inputc := make(chan string) @@ -2187,7 +2188,7 @@ func TestDeploy(t *testing.T) { // Call `app.Run()` and wait for response go func() { - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.args, nil) @@ -2215,8 +2216,8 @@ func TestDeploy(t *testing.T) { if len(testcase.stdin) > 0 { stdin = testcase.stdin[0] } - opts.Stdin = strings.NewReader(stdin) - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + opts.Input = strings.NewReader(stdin) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.args, nil) diff --git a/pkg/commands/compute/init.go b/pkg/commands/compute/init.go index 18b755f16..d508ed5cf 100644 --- a/pkg/commands/compute/init.go +++ b/pkg/commands/compute/init.go @@ -43,7 +43,6 @@ type InitCommand struct { dir string cloneFrom string language string - manifest manifest.Data tag string } @@ -51,13 +50,12 @@ type InitCommand struct { var Languages = []string{"rust", "javascript", "go", "other"} // NewInitCommand returns a usable command registered under the parent. -func NewInitCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *InitCommand { +func NewInitCommand(parent cmd.Registerer, g *global.Data) *InitCommand { var c InitCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("init", "Initialize a new Compute package locally") - c.CmdClause.Flag("author", "Author(s) of the package").Short('a').StringsVar(&c.manifest.File.Authors) + c.CmdClause.Flag("author", "Author(s) of the package").Short('a').StringsVar(&g.Manifest.File.Authors) c.CmdClause.Flag("branch", "Git branch name to clone from package template repository").Hidden().StringVar(&c.branch) c.CmdClause.Flag("directory", "Destination to write the new package, defaulting to the current directory").Short('p').StringVar(&c.dir) c.CmdClause.Flag("from", "Local project directory, or Git repository URL, or URL referencing a .zip/.tar.gz file, containing a package template").Short('f').StringVar(&c.cloneFrom) @@ -106,7 +104,7 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) { return fmt.Errorf("error determining current directory: %w", err) } - mf := c.manifest.File + mf := c.Globals.Manifest.File if c.Globals.Flags.Quiet { mf.SetQuiet(true) } @@ -441,9 +439,9 @@ func validateDirectoryPermissions(dst string) text.SpinnerProcess { // returned as is. func (c *InitCommand) PromptOrReturn(email string, in io.Reader, out io.Writer) (name, description string, authors []string, err error) { flags := c.Globals.Flags - name, _ = c.manifest.Name() - description, _ = c.manifest.Description() - authors, _ = c.manifest.Authors() + name, _ = c.Globals.Manifest.Name() + description, _ = c.Globals.Manifest.Description() + authors, _ = c.Globals.Manifest.Authors() if name == "" && !flags.AcceptDefaults && !flags.NonInteractive { text.Break(out) diff --git a/pkg/commands/compute/init_test.go b/pkg/commands/compute/init_test.go index f427fb0f3..ecfc161d7 100644 --- a/pkg/commands/compute/init_test.go +++ b/pkg/commands/compute/init_test.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/config" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/testutil" ) @@ -359,14 +360,14 @@ func TestInit(t *testing.T) { }() var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) - opts.ConfigFile = testcase.configFile + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) + opts.Config = testcase.configFile // we need to define stdin as the init process prompts the user multiple // times, but we don't need to provide any values as all our prompts will // fallback to default values if the input is unrecognised. - opts.Stdin = strings.NewReader(testcase.stdin) + opts.Input = strings.NewReader(testcase.stdin) return opts, nil } err = app.Run(testcase.args, nil) diff --git a/pkg/commands/compute/metadata_test.go b/pkg/commands/compute/metadata_test.go index 1083469a9..0c756682b 100644 --- a/pkg/commands/compute/metadata_test.go +++ b/pkg/commands/compute/metadata_test.go @@ -12,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/config" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/revision" "github.com/fastly/cli/pkg/testutil" ) @@ -124,7 +125,7 @@ func TestMetadata(t *testing.T) { t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) // We override the config path so that we don't accidentally write over // our own configuration file. @@ -141,14 +142,14 @@ func TestMetadata(t *testing.T) { // The read of the config file only happens in the main() function, so for // the sake of the test environment we need to construct an in-memory // representation of the config file we want to be using. - opts.ConfigFile = config.File{ + opts.Config = config.File{ ConfigVersion: staticConfig.ConfigVersion, CLI: config.CLI{ Version: revision.SemVer(revision.AppVersion), }, } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -163,19 +164,19 @@ func TestMetadata(t *testing.T) { in := strings.NewReader("") verboseMode := false - err = opts.ConfigFile.Read(configPath, in, opts.Stdout, opts.ErrLog, verboseMode) + err = opts.Config.Read(configPath, in, opts.Output, opts.ErrLog, verboseMode) if err != nil { t.Error(err) } - if opts.ConfigFile.WasmMetadata.BuildInfo != testcase.ExpectedConfig.BuildInfo { - t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.BuildInfo, opts.ConfigFile.WasmMetadata.BuildInfo) + if opts.Config.WasmMetadata.BuildInfo != testcase.ExpectedConfig.BuildInfo { + t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.BuildInfo, opts.Config.WasmMetadata.BuildInfo) } - if opts.ConfigFile.WasmMetadata.MachineInfo != testcase.ExpectedConfig.MachineInfo { - t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.MachineInfo, opts.ConfigFile.WasmMetadata.MachineInfo) + if opts.Config.WasmMetadata.MachineInfo != testcase.ExpectedConfig.MachineInfo { + t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.MachineInfo, opts.Config.WasmMetadata.MachineInfo) } - if opts.ConfigFile.WasmMetadata.PackageInfo != testcase.ExpectedConfig.PackageInfo { - t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.PackageInfo, opts.ConfigFile.WasmMetadata.PackageInfo) + if opts.Config.WasmMetadata.PackageInfo != testcase.ExpectedConfig.PackageInfo { + t.Errorf("want: %s, got: %s", testcase.ExpectedConfig.PackageInfo, opts.Config.WasmMetadata.PackageInfo) } }) } diff --git a/pkg/commands/compute/pack.go b/pkg/commands/compute/pack.go index 3afbaff46..3d551257d 100644 --- a/pkg/commands/compute/pack.go +++ b/pkg/commands/compute/pack.go @@ -19,16 +19,13 @@ import ( // PackCommand takes a .wasm and builds the required tar/gzip package ready to be uploaded. type PackCommand struct { cmd.Base - manifest manifest.Data wasmBinary string } // NewPackCommand returns a usable command registered under the parent. -func NewPackCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *PackCommand { +func NewPackCommand(parent cmd.Registerer, g *global.Data) *PackCommand { var c PackCommand c.Globals = g - c.manifest = m - c.CmdClause = parent.Command("pack", "Package a pre-compiled Wasm binary for a Fastly Compute service") c.CmdClause.Flag("wasm-binary", "Path to a pre-compiled Wasm binary").Short('w').Required().StringVar(&c.wasmBinary) @@ -51,7 +48,7 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) { } }(c.Globals.ErrLog) - if err = c.manifest.File.ReadError(); err != nil { + if err = c.Globals.Manifest.File.ReadError(); err != nil { return err } diff --git a/pkg/commands/compute/pack_test.go b/pkg/commands/compute/pack_test.go index 1757c6aa3..905cd691e 100644 --- a/pkg/commands/compute/pack_test.go +++ b/pkg/commands/compute/pack_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/testutil" ) @@ -82,8 +83,8 @@ func TestPack(t *testing.T) { }() var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - return testutil.NewRunOpts(testcase.args, &stdout), nil + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + return testutil.MockGlobalData(testcase.args, &stdout), nil } err = app.Run(testcase.args, nil) diff --git a/pkg/commands/compute/serve.go b/pkg/commands/compute/serve.go index 9cc9045cf..f4563a30b 100644 --- a/pkg/commands/compute/serve.go +++ b/pkg/commands/compute/serve.go @@ -71,13 +71,11 @@ type ServeCommand struct { } // NewServeCommand returns a usable command registered under the parent. -func NewServeCommand(parent cmd.Registerer, g *global.Data, build *BuildCommand, viceroyVersioner github.AssetVersioner) *ServeCommand { +func NewServeCommand(parent cmd.Registerer, g *global.Data, build *BuildCommand) *ServeCommand { var c ServeCommand - c.build = build - c.ViceroyVersioner = viceroyVersioner - c.Globals = g + c.ViceroyVersioner = g.Versioners.Viceroy c.CmdClause = parent.Command("serve", "Build and run a Compute package locally") c.CmdClause.Flag("addr", "The IPv4 address and port to listen on").Default("127.0.0.1:7676").StringVar(&c.addr) diff --git a/pkg/commands/compute/update.go b/pkg/commands/compute/update.go index cf274c08d..99ddf21d3 100644 --- a/pkg/commands/compute/update.go +++ b/pkg/commands/compute/update.go @@ -18,7 +18,6 @@ import ( // UpdateCommand calls the Fastly API to update packages. type UpdateCommand struct { cmd.Base - manifest manifest.Data path string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -26,18 +25,17 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a package on a Fastly Compute service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) (err error) { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, @@ -81,7 +79,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) (err error) { packagePath := c.path if packagePath == "" { - projectName, source := c.manifest.Name() + projectName, source := c.Globals.Manifest.Name() if source == manifest.SourceUndefined { return fsterr.RemediationError{ Inner: fmt.Errorf("failed to read project name: %w", fsterr.ErrReadingManifest), diff --git a/pkg/commands/compute/update_test.go b/pkg/commands/compute/update_test.go index dd5426995..85c6a659f 100644 --- a/pkg/commands/compute/update_test.go +++ b/pkg/commands/compute/update_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -76,8 +77,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/compute/validate_test.go b/pkg/commands/compute/validate_test.go index ff331dc0d..152768f44 100644 --- a/pkg/commands/compute/validate_test.go +++ b/pkg/commands/compute/validate_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/testutil" ) @@ -54,8 +55,8 @@ func TestValidate(t *testing.T) { }() var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - return testutil.NewRunOpts(testcase.Args, &stdout), nil + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + return testutil.MockGlobalData(testcase.Args, &stdout), nil } err = app.Run(testcase.Args, nil) testutil.AssertErrorContains(t, err, testcase.WantError) diff --git a/pkg/commands/config/config_test.go b/pkg/commands/config/config_test.go index 2afd73c30..caa14fa97 100644 --- a/pkg/commands/config/config_test.go +++ b/pkg/commands/config/config_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -71,8 +72,8 @@ func TestConfig(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) opts.ConfigPath = configPath return opts, nil diff --git a/pkg/commands/configstore/configstore_test.go b/pkg/commands/configstore/configstore_test.go index 4e79579f2..9c47d4abe 100644 --- a/pkg/commands/configstore/configstore_test.go +++ b/pkg/commands/configstore/configstore_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/configstore" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -75,8 +76,8 @@ func TestCreateStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -138,8 +139,8 @@ func TestDeleteStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -242,8 +243,8 @@ func TestDescribeStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -310,8 +311,8 @@ func TestListStoresCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -376,8 +377,8 @@ func TestListStoreServicesCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -447,8 +448,8 @@ func TestUpdateStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/configstore/create.go b/pkg/commands/configstore/create.go index a4ba6d36e..c00e29052 100644 --- a/pkg/commands/configstore/create.go +++ b/pkg/commands/configstore/create.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new config store") @@ -42,9 +40,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C type CreateCommand struct { cmd.Base cmd.JSONOutput - - input fastly.CreateConfigStoreInput - manifest manifest.Data + input fastly.CreateConfigStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstore/delete.go b/pkg/commands/configstore/delete.go index af019dbe6..484ce746d 100644 --- a/pkg/commands/configstore/delete.go +++ b/pkg/commands/configstore/delete.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a config store") @@ -36,9 +34,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base cmd.JSONOutput - - input fastly.DeleteConfigStoreInput - manifest manifest.Data + input fastly.DeleteConfigStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstore/describe.go b/pkg/commands/configstore/describe.go index ebb5935ab..82fa7d1bd 100644 --- a/pkg/commands/configstore/describe.go +++ b/pkg/commands/configstore/describe.go @@ -3,21 +3,20 @@ package configstore import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single config store").Alias("get") @@ -41,9 +40,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) type DescribeCommand struct { cmd.Base cmd.JSONOutput - input fastly.GetConfigStoreInput - manifest manifest.Data metadata bool } diff --git a/pkg/commands/configstore/list.go b/pkg/commands/configstore/list.go index 6dd3a3a48..03187f3ef 100644 --- a/pkg/commands/configstore/list.go +++ b/pkg/commands/configstore/list.go @@ -6,17 +6,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List config stores") @@ -31,8 +29,6 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis type ListCommand struct { cmd.Base cmd.JSONOutput - - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstore/list_services.go b/pkg/commands/configstore/list_services.go index 807b8e0cf..8031da294 100644 --- a/pkg/commands/configstore/list_services.go +++ b/pkg/commands/configstore/list_services.go @@ -3,21 +3,20 @@ package configstore import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListServicesCommand returns a usable command registered under the parent. -func NewListServicesCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListServicesCommand { +func NewListServicesCommand(parent cmd.Registerer, g *global.Data) *ListServicesCommand { c := ListServicesCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list-services", "List config store's services") @@ -35,9 +34,7 @@ func NewListServicesCommand(parent cmd.Registerer, g *global.Data, m manifest.Da type ListServicesCommand struct { cmd.Base cmd.JSONOutput - - input fastly.ListConfigStoreServicesInput - manifest manifest.Data + input fastly.ListConfigStoreServicesInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstore/update.go b/pkg/commands/configstore/update.go index 0e1409d52..bdbe5f444 100644 --- a/pkg/commands/configstore/update.go +++ b/pkg/commands/configstore/update.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a config store") @@ -43,9 +41,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U type UpdateCommand struct { cmd.Base cmd.JSONOutput - - input fastly.UpdateConfigStoreInput - manifest manifest.Data + input fastly.UpdateConfigStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstoreentry/configstoreentry_test.go b/pkg/commands/configstoreentry/configstoreentry_test.go index cfdafca0f..693d1a954 100644 --- a/pkg/commands/configstoreentry/configstoreentry_test.go +++ b/pkg/commands/configstoreentry/configstoreentry_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/configstoreentry" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" "github.com/fastly/cli/pkg/text" @@ -81,8 +82,8 @@ func TestCreateEntryCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -199,8 +200,8 @@ SUCCESS: Deleted all keys from Config Store '%s' testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -277,8 +278,8 @@ func TestDescribeEntryCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -343,8 +344,8 @@ func TestListEntriesCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -417,8 +418,8 @@ func TestUpdateEntryCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/configstoreentry/create.go b/pkg/commands/configstoreentry/create.go index 63d890457..65ffb3967 100644 --- a/pkg/commands/configstoreentry/create.go +++ b/pkg/commands/configstoreentry/create.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new config store item").Alias("insert") @@ -57,10 +55,8 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C type CreateCommand struct { cmd.Base cmd.JSONOutput - - input fastly.CreateConfigStoreItemInput - stdin bool - manifest manifest.Data + input fastly.CreateConfigStoreItemInput + stdin bool } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstoreentry/delete.go b/pkg/commands/configstoreentry/delete.go index 8065c3ce9..dfd36cc7f 100644 --- a/pkg/commands/configstoreentry/delete.go +++ b/pkg/commands/configstoreentry/delete.go @@ -11,7 +11,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -24,12 +23,11 @@ const deleteKeysConcurrencyLimit int = 100 const batchLimit int = 100 // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a config store item") @@ -61,7 +59,6 @@ type DeleteCommand struct { concurrency cmd.OptionalInt deleteAll bool input fastly.DeleteConfigStoreItemInput - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstoreentry/describe.go b/pkg/commands/configstoreentry/describe.go index 6cc5a8db6..d55586b2f 100644 --- a/pkg/commands/configstoreentry/describe.go +++ b/pkg/commands/configstoreentry/describe.go @@ -3,21 +3,20 @@ package configstoreentry import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single config store item").Alias("get") @@ -42,9 +41,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) type DescribeCommand struct { cmd.Base cmd.JSONOutput - - input fastly.GetConfigStoreItemInput - manifest manifest.Data + input fastly.GetConfigStoreItemInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstoreentry/list.go b/pkg/commands/configstoreentry/list.go index 588ec9faf..1485ed698 100644 --- a/pkg/commands/configstoreentry/list.go +++ b/pkg/commands/configstoreentry/list.go @@ -3,21 +3,20 @@ package configstoreentry import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List config store items") @@ -35,9 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis type ListCommand struct { cmd.Base cmd.JSONOutput - - input fastly.ListConfigStoreItemsInput - manifest manifest.Data + input fastly.ListConfigStoreItemsInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/configstoreentry/update.go b/pkg/commands/configstoreentry/update.go index 9ba313554..bd845e103 100644 --- a/pkg/commands/configstoreentry/update.go +++ b/pkg/commands/configstoreentry/update.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a config store item") @@ -63,10 +61,8 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U type UpdateCommand struct { cmd.Base cmd.JSONOutput - - input fastly.UpdateConfigStoreItemInput - stdin bool - manifest manifest.Data + input fastly.UpdateConfigStoreItemInput + stdin bool } // Exec invokes the application logic for the command. diff --git a/pkg/commands/dictionary/create.go b/pkg/commands/dictionary/create.go index ca098f826..7abd04191 100644 --- a/pkg/commands/dictionary/create.go +++ b/pkg/commands/dictionary/create.go @@ -8,14 +8,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // CreateCommand calls the Fastly API to create a service. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceVersion cmd.OptionalServiceVersion @@ -28,12 +26,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a Fastly edge dictionary on a Fastly service version") @@ -54,7 +51,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -72,7 +69,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/dictionary/delete.go b/pkg/commands/dictionary/delete.go index 04776f150..598d25f16 100644 --- a/pkg/commands/dictionary/delete.go +++ b/pkg/commands/dictionary/delete.go @@ -8,14 +8,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // DeleteCommand calls the Fastly API to delete a service. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteDictionaryInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -23,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Fastly edge dictionary from a Fastly service version") @@ -49,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -66,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/dictionary/describe.go b/pkg/commands/dictionary/describe.go index b6a3ca99e..dbd4a36a7 100644 --- a/pkg/commands/dictionary/describe.go +++ b/pkg/commands/dictionary/describe.go @@ -3,12 +3,12 @@ package dictionary import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a dictionary. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetDictionaryInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Fastly edge dictionary").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/dictionary/dictionary_test.go b/pkg/commands/dictionary/dictionary_test.go index 8157c900c..cd54e10a3 100644 --- a/pkg/commands/dictionary/dictionary_test.go +++ b/pkg/commands/dictionary/dictionary_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -57,8 +58,8 @@ func TestDictionaryDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -121,8 +122,8 @@ func TestDictionaryCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -168,8 +169,8 @@ func TestDeleteDictionary(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -213,8 +214,8 @@ func TestListDictionary(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -303,8 +304,8 @@ func TestUpdateDictionary(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/dictionary/list.go b/pkg/commands/dictionary/list.go index 2a345df16..65cada422 100644 --- a/pkg/commands/dictionary/list.go +++ b/pkg/commands/dictionary/list.go @@ -9,7 +9,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -18,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListDictionariesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List all dictionaries on a Fastly service version") @@ -47,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +64,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/dictionary/update.go b/pkg/commands/dictionary/update.go index f7cd41dc8..5e98948b2 100644 --- a/pkg/commands/dictionary/update.go +++ b/pkg/commands/dictionary/update.go @@ -10,14 +10,13 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // UpdateCommand calls the Fastly API to update a dictionary. type UpdateCommand struct { cmd.Base - manifest manifest.Data + // TODO: make input consistent across commands (most are title case) input fastly.UpdateDictionaryInput serviceName cmd.OptionalServiceNameID @@ -29,12 +28,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update name of dictionary on a Fastly service version").Alias("get") @@ -56,7 +54,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -74,7 +72,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/dictionaryentry/create.go b/pkg/commands/dictionaryentry/create.go index 82dcefda9..2f347a8e8 100644 --- a/pkg/commands/dictionaryentry/create.go +++ b/pkg/commands/dictionaryentry/create.go @@ -7,25 +7,22 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // CreateCommand calls the Fastly API to create a dictionary item. type CreateCommand struct { cmd.Base - manifest manifest.Data Input fastly.CreateDictionaryItemInput serviceName cmd.OptionalServiceNameID } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new item on a Fastly edge dictionary") @@ -38,7 +35,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -52,7 +49,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/dictionaryentry/delete.go b/pkg/commands/dictionaryentry/delete.go index c78886306..7220e3815 100644 --- a/pkg/commands/dictionaryentry/delete.go +++ b/pkg/commands/dictionaryentry/delete.go @@ -7,25 +7,22 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // DeleteCommand calls the Fastly API to delete a service. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteDictionaryItemInput serviceName cmd.OptionalServiceNameID } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an item from a Fastly edge dictionary") @@ -37,7 +34,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -51,7 +48,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/dictionaryentry/describe.go b/pkg/commands/dictionaryentry/describe.go index a1afa9629..5bd265194 100644 --- a/pkg/commands/dictionaryentry/describe.go +++ b/pkg/commands/dictionaryentry/describe.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a dictionary item. @@ -17,18 +17,16 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetDictionaryItemInput serviceName cmd.OptionalServiceNameID } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Fastly edge dictionary item").Alias("get") @@ -41,7 +39,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -60,7 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/dictionaryentry/dictionaryitem_test.go b/pkg/commands/dictionaryentry/dictionaryitem_test.go index 242a9f9d1..f2d2df4be 100644 --- a/pkg/commands/dictionaryentry/dictionaryitem_test.go +++ b/pkg/commands/dictionaryentry/dictionaryitem_test.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -48,8 +49,8 @@ func TestDictionaryItemDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -176,8 +177,8 @@ func TestDictionaryItemsList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -216,8 +217,8 @@ func TestDictionaryItemCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -295,8 +296,8 @@ func TestDictionaryItemUpdate(t *testing.T) { } var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -335,8 +336,8 @@ func TestDictionaryItemDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/dictionaryentry/list.go b/pkg/commands/dictionaryentry/list.go index c07149ad1..c581d116d 100644 --- a/pkg/commands/dictionaryentry/list.go +++ b/pkg/commands/dictionaryentry/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list dictionary items. @@ -17,18 +17,16 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data input fastly.ListDictionaryItemsInput serviceName cmd.OptionalServiceNameID } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List items in a Fastly edge dictionary") @@ -43,7 +41,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -62,7 +60,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/dictionaryentry/update.go b/pkg/commands/dictionaryentry/update.go index 8a13fc06c..ee50f9ffa 100644 --- a/pkg/commands/dictionaryentry/update.go +++ b/pkg/commands/dictionaryentry/update.go @@ -10,7 +10,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -21,17 +20,15 @@ type UpdateCommand struct { Input fastly.UpdateDictionaryItemInput InputBatch fastly.BatchModifyDictionaryItemsInput file cmd.OptionalString - manifest manifest.Data serviceName cmd.OptionalServiceNameID } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update or insert an item on a Fastly edge dictionary") @@ -44,7 +41,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -59,7 +56,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/doc.go b/pkg/commands/doc.go new file mode 100644 index 000000000..41caccb96 --- /dev/null +++ b/pkg/commands/doc.go @@ -0,0 +1,2 @@ +// Package commands contains functions for managing exposed CLI commands. +package commands diff --git a/pkg/commands/domain/create.go b/pkg/commands/domain/create.go index 733ed81cf..9d731aab5 100644 --- a/pkg/commands/domain/create.go +++ b/pkg/commands/domain/create.go @@ -3,18 +3,17 @@ package domain import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create domains. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceVersion cmd.OptionalServiceVersion @@ -27,12 +26,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a domain on a Fastly service version").Alias("add") @@ -54,7 +52,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -71,7 +69,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/domain/delete.go b/pkg/commands/domain/delete.go index 994f6a911..b41360af8 100644 --- a/pkg/commands/domain/delete.go +++ b/pkg/commands/domain/delete.go @@ -3,18 +3,17 @@ package domain import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete domains. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteDomainInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a domain on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/domain/describe.go b/pkg/commands/domain/describe.go index 863e64b24..0bb2c4c65 100644 --- a/pkg/commands/domain/describe.go +++ b/pkg/commands/domain/describe.go @@ -4,11 +4,11 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a domain. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetDomainInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a domain on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/domain/domain_test.go b/pkg/commands/domain/domain_test.go index 2e152d742..ea06f0e8d 100644 --- a/pkg/commands/domain/domain_test.go +++ b/pkg/commands/domain/domain_test.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestDomainCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -113,8 +114,8 @@ func TestDomainList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -153,8 +154,8 @@ func TestDomainDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -204,8 +205,8 @@ func TestDomainUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -246,8 +247,8 @@ func TestDomainDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -334,8 +335,8 @@ func TestDomainValidate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/domain/list.go b/pkg/commands/domain/list.go index d2495fe6f..96044799e 100644 --- a/pkg/commands/domain/list.go +++ b/pkg/commands/domain/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list domains. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListDomainsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List domains on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/domain/update.go b/pkg/commands/domain/update.go index 9421d7afc..6530c48bc 100644 --- a/pkg/commands/domain/update.go +++ b/pkg/commands/domain/update.go @@ -4,18 +4,17 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update domains. type UpdateCommand struct { cmd.Base - manifest manifest.Data input fastly.UpdateDomainInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -26,12 +25,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a domain on a Fastly service version") @@ -54,7 +52,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -71,7 +69,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/domain/validate.go b/pkg/commands/domain/validate.go index 25b088ab3..3aaeec5c8 100644 --- a/pkg/commands/domain/validate.go +++ b/pkg/commands/domain/validate.go @@ -9,15 +9,13 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // NewValidateCommand returns a usable command registered under the parent. -func NewValidateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ValidateCommand { +func NewValidateCommand(parent cmd.Registerer, g *global.Data) *ValidateCommand { var c ValidateCommand c.CmdClause = parent.Command("validate", "Checks the status of a specific domain's DNS record for a Service Version") c.Globals = g - c.manifest = m // Required. c.RegisterFlag(cmd.StringFlagOpts{ @@ -33,7 +31,7 @@ func NewValidateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -51,7 +49,6 @@ type ValidateCommand struct { cmd.Base all bool - manifest manifest.Data name cmd.OptionalString serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -62,7 +59,7 @@ func (c *ValidateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/healthcheck/create.go b/pkg/commands/healthcheck/create.go index e1642e076..b2bd368ca 100644 --- a/pkg/commands/healthcheck/create.go +++ b/pkg/commands/healthcheck/create.go @@ -3,18 +3,17 @@ package healthcheck import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create healthchecks. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceVersion cmd.OptionalServiceVersion @@ -37,12 +36,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a healthcheck on a Fastly service version").Alias("add") @@ -71,7 +69,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -91,7 +89,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/healthcheck/delete.go b/pkg/commands/healthcheck/delete.go index 3fd8c6624..a003c1098 100644 --- a/pkg/commands/healthcheck/delete.go +++ b/pkg/commands/healthcheck/delete.go @@ -3,18 +3,17 @@ package healthcheck import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete healthchecks. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteHealthCheckInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a healthcheck on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/healthcheck/describe.go b/pkg/commands/healthcheck/describe.go index 72222f2d9..342854e7d 100644 --- a/pkg/commands/healthcheck/describe.go +++ b/pkg/commands/healthcheck/describe.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a healthcheck. @@ -17,19 +17,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetHealthCheckInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a healthcheck on a Fastly service version").Alias("get") @@ -47,7 +45,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -68,7 +66,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/healthcheck/healthcheck_test.go b/pkg/commands/healthcheck/healthcheck_test.go index 3f2fcaa2d..e9a4c838a 100644 --- a/pkg/commands/healthcheck/healthcheck_test.go +++ b/pkg/commands/healthcheck/healthcheck_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -51,8 +52,8 @@ func TestHealthCheckCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -124,8 +125,8 @@ func TestHealthCheckList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -169,8 +170,8 @@ func TestHealthCheckDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -224,8 +225,8 @@ func TestHealthCheckUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -271,8 +272,8 @@ func TestHealthCheckDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/healthcheck/list.go b/pkg/commands/healthcheck/list.go index fa910e371..5096056c4 100644 --- a/pkg/commands/healthcheck/list.go +++ b/pkg/commands/healthcheck/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list healthchecks. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListHealthChecksInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List healthchecks on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/healthcheck/update.go b/pkg/commands/healthcheck/update.go index ac7ca536e..700b77b53 100644 --- a/pkg/commands/healthcheck/update.go +++ b/pkg/commands/healthcheck/update.go @@ -3,18 +3,17 @@ package healthcheck import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update healthchecks. type UpdateCommand struct { cmd.Base - manifest manifest.Data input fastly.UpdateHealthCheckInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -35,12 +34,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a healthcheck on a Fastly service version") @@ -70,7 +68,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -90,7 +88,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/ip/ip_test.go b/pkg/commands/ip/ip_test.go index da5ff3bb7..f905a6bde 100644 --- a/pkg/commands/ip/ip_test.go +++ b/pkg/commands/ip/ip_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -24,8 +25,8 @@ func TestAllIPs(t *testing.T) { }, nil }, } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(args, &stdout) opts.APIClientFactory = mock.APIClient(api) return opts, nil } diff --git a/pkg/commands/kvstore/create.go b/pkg/commands/kvstore/create.go index c994f5d1d..a29252239 100644 --- a/pkg/commands/kvstore/create.go +++ b/pkg/commands/kvstore/create.go @@ -8,7 +8,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -17,17 +16,15 @@ type CreateCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.CreateKVStoreInput + Input fastly.CreateKVStoreInput } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create an kv store") c.CmdClause.Flag("name", "Name of KV Store").Short('n').Required().StringVar(&c.Input.Name) diff --git a/pkg/commands/kvstore/delete.go b/pkg/commands/kvstore/delete.go index a379bb254..eaff97dfc 100644 --- a/pkg/commands/kvstore/delete.go +++ b/pkg/commands/kvstore/delete.go @@ -8,7 +8,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -17,17 +16,15 @@ type DeleteCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.DeleteKVStoreInput + Input fastly.DeleteKVStoreInput } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an kv store") diff --git a/pkg/commands/kvstore/describe.go b/pkg/commands/kvstore/describe.go index ad0a26249..db83b0c2d 100644 --- a/pkg/commands/kvstore/describe.go +++ b/pkg/commands/kvstore/describe.go @@ -8,7 +8,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -17,17 +16,15 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.GetKVStoreInput + Input fastly.GetKVStoreInput } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Describe an kv store").Alias("get") diff --git a/pkg/commands/kvstore/kvstore_test.go b/pkg/commands/kvstore/kvstore_test.go index fdfbc87c7..966c7bf35 100644 --- a/pkg/commands/kvstore/kvstore_test.go +++ b/pkg/commands/kvstore/kvstore_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/kvstore" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" "github.com/fastly/cli/pkg/text" @@ -76,8 +77,8 @@ func TestCreateStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -139,8 +140,8 @@ func TestDeleteStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -217,8 +218,8 @@ func TestDescribeStoreCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -287,8 +288,8 @@ func TestListStoresCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/kvstore/list.go b/pkg/commands/kvstore/list.go index 659ece4eb..e69f3cce2 100644 --- a/pkg/commands/kvstore/list.go +++ b/pkg/commands/kvstore/list.go @@ -8,7 +8,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -16,17 +15,14 @@ import ( type ListCommand struct { cmd.Base cmd.JSONOutput - - manifest manifest.Data } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List kv stores") diff --git a/pkg/commands/kvstoreentry/create.go b/pkg/commands/kvstoreentry/create.go index f2a7c3ebb..72bdf05f8 100644 --- a/pkg/commands/kvstoreentry/create.go +++ b/pkg/commands/kvstoreentry/create.go @@ -17,18 +17,16 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/runtime" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Insert a key-value pair").Alias("insert") @@ -57,7 +55,6 @@ type CreateCommand struct { dirConcurrency int dirPath string filePath string - manifest manifest.Data stdin bool Input fastly.InsertKVStoreKeyInput diff --git a/pkg/commands/kvstoreentry/delete.go b/pkg/commands/kvstoreentry/delete.go index a8f5355e6..e5dd78bde 100644 --- a/pkg/commands/kvstoreentry/delete.go +++ b/pkg/commands/kvstoreentry/delete.go @@ -12,7 +12,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -28,17 +27,15 @@ type DeleteCommand struct { concurrency cmd.OptionalInt deleteAll bool key cmd.OptionalString - manifest manifest.Data storeID string } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a key") diff --git a/pkg/commands/kvstoreentry/describe.go b/pkg/commands/kvstoreentry/describe.go index b93fb574f..087cd8167 100644 --- a/pkg/commands/kvstoreentry/describe.go +++ b/pkg/commands/kvstoreentry/describe.go @@ -9,7 +9,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -18,17 +17,15 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.GetKVStoreKeyInput + Input fastly.GetKVStoreKeyInput } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the value associated with a key").Alias("get") diff --git a/pkg/commands/kvstoreentry/kvstoreentry_test.go b/pkg/commands/kvstoreentry/kvstoreentry_test.go index fbcf406d9..9225d0aaf 100644 --- a/pkg/commands/kvstoreentry/kvstoreentry_test.go +++ b/pkg/commands/kvstoreentry/kvstoreentry_test.go @@ -14,6 +14,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/kvstoreentry" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" "github.com/fastly/cli/pkg/threadsafe" @@ -128,11 +129,11 @@ func TestCreateCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) if testcase.Stdin != nil { - opts.Stdin = testcase.Stdin + opts.Input = testcase.Stdin } return opts, nil } @@ -251,8 +252,8 @@ SUCCESS: Deleted all keys from KV Store '%s' testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -309,8 +310,8 @@ func TestDescribeCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -367,8 +368,8 @@ func TestListCommand(t *testing.T) { testcase := testcase t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/kvstoreentry/list.go b/pkg/commands/kvstoreentry/list.go index 2cf3fd386..31f0f481e 100644 --- a/pkg/commands/kvstoreentry/list.go +++ b/pkg/commands/kvstoreentry/list.go @@ -9,7 +9,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -19,7 +18,6 @@ type ListCommand struct { cmd.JSONOutput consistency string - manifest manifest.Data Input fastly.ListKVStoreKeysInput } @@ -30,12 +28,11 @@ var ConsistencyOptions = []string{ } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List keys") diff --git a/pkg/commands/logging/azureblob/azureblob_integration_test.go b/pkg/commands/logging/azureblob/azureblob_integration_test.go index 0caf19261..54a56539a 100644 --- a/pkg/commands/logging/azureblob/azureblob_integration_test.go +++ b/pkg/commands/logging/azureblob/azureblob_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -54,8 +55,8 @@ func TestBlobStorageCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -127,8 +128,8 @@ func TestBlobStorageList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -172,8 +173,8 @@ func TestBlobStorageDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -219,8 +220,8 @@ func TestBlobStorageUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -266,8 +267,8 @@ func TestBlobStorageDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/azureblob/create.go b/pkg/commands/logging/azureblob/create.go index 41a9c8f6c..cee048b6a 100644 --- a/pkg/commands/logging/azureblob/create.go +++ b/pkg/commands/logging/azureblob/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an Azure Blob Storage logging endpoint. @@ -43,12 +44,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an Azure Blob Storage logging endpoint on a Fastly service version").Alias("add") @@ -83,7 +83,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -181,7 +181,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/azureblob/delete.go b/pkg/commands/logging/azureblob/delete.go index 8a92c228e..12b1cd75f 100644 --- a/pkg/commands/logging/azureblob/delete.go +++ b/pkg/commands/logging/azureblob/delete.go @@ -3,18 +3,17 @@ package azureblob import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an Azure Blob Storage logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteBlobStorageInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an Azure Blob Storage logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/azureblob/describe.go b/pkg/commands/logging/azureblob/describe.go index d37b6c60f..335f23e35 100644 --- a/pkg/commands/logging/azureblob/describe.go +++ b/pkg/commands/logging/azureblob/describe.go @@ -3,12 +3,12 @@ package azureblob import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an Azure Blob Storage logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetBlobStorageInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an Azure Blob Storage logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/azureblob/list.go b/pkg/commands/logging/azureblob/list.go index 5f950a64d..1534fbbe1 100644 --- a/pkg/commands/logging/azureblob/list.go +++ b/pkg/commands/logging/azureblob/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Azure Blob Storage logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListBlobStoragesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Azure Blob Storage logging endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/azureblob/update.go b/pkg/commands/logging/azureblob/update.go index 5e0c6956f..51724ca36 100644 --- a/pkg/commands/logging/azureblob/update.go +++ b/pkg/commands/logging/azureblob/update.go @@ -3,13 +3,14 @@ package azureblob import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an Azure Blob Storage logging endpoint. @@ -43,12 +44,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an Azure Blob Storage logging endpoint on a Fastly service version") @@ -86,7 +86,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -180,7 +180,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/bigquery/bigquery_integration_test.go b/pkg/commands/logging/bigquery/bigquery_integration_test.go index 324ea7c96..a11cec0ac 100644 --- a/pkg/commands/logging/bigquery/bigquery_integration_test.go +++ b/pkg/commands/logging/bigquery/bigquery_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestBigQueryCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestBigQueryList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestBigQueryDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestBigQueryUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestBigQueryDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/bigquery/create.go b/pkg/commands/logging/bigquery/create.go index d97d082b8..c2c822793 100644 --- a/pkg/commands/logging/bigquery/create.go +++ b/pkg/commands/logging/bigquery/create.go @@ -39,12 +39,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a BigQuery logging endpoint on a Fastly service version").Alias("add") @@ -73,7 +72,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -140,7 +139,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/bigquery/delete.go b/pkg/commands/logging/bigquery/delete.go index f18a1370c..a9c20ddf2 100644 --- a/pkg/commands/logging/bigquery/delete.go +++ b/pkg/commands/logging/bigquery/delete.go @@ -3,18 +3,17 @@ package bigquery import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a BigQuery logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteBigQueryInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a BigQuery logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/bigquery/describe.go b/pkg/commands/logging/bigquery/describe.go index bdab599cd..9a08ed428 100644 --- a/pkg/commands/logging/bigquery/describe.go +++ b/pkg/commands/logging/bigquery/describe.go @@ -3,12 +3,12 @@ package bigquery import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a BigQuery logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetBigQueryInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a BigQuery logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/bigquery/list.go b/pkg/commands/logging/bigquery/list.go index 7b8b10b70..4966edd49 100644 --- a/pkg/commands/logging/bigquery/list.go +++ b/pkg/commands/logging/bigquery/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list BigQuery logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListBigQueriesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List BigQuery endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/bigquery/update.go b/pkg/commands/logging/bigquery/update.go index 570069bb3..868eb6bcd 100644 --- a/pkg/commands/logging/bigquery/update.go +++ b/pkg/commands/logging/bigquery/update.go @@ -40,12 +40,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a BigQuery logging endpoint on a Fastly service version") @@ -75,7 +74,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -143,7 +142,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/cloudfiles/cloudfiles_integration_test.go b/pkg/commands/logging/cloudfiles/cloudfiles_integration_test.go index c4a3636f6..de88f74e7 100644 --- a/pkg/commands/logging/cloudfiles/cloudfiles_integration_test.go +++ b/pkg/commands/logging/cloudfiles/cloudfiles_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestCloudfilesCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestCloudfilesList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestCloudfilesDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestCloudfilesUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestCloudfilesDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/cloudfiles/create.go b/pkg/commands/logging/cloudfiles/create.go index 56912c910..75e11edc7 100644 --- a/pkg/commands/logging/cloudfiles/create.go +++ b/pkg/commands/logging/cloudfiles/create.go @@ -45,12 +45,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Cloudfiles logging endpoint on a Fastly service version").Alias("add") @@ -84,7 +83,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -179,7 +178,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/cloudfiles/delete.go b/pkg/commands/logging/cloudfiles/delete.go index 417f23a75..f0c87bfde 100644 --- a/pkg/commands/logging/cloudfiles/delete.go +++ b/pkg/commands/logging/cloudfiles/delete.go @@ -3,18 +3,17 @@ package cloudfiles import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Cloudfiles logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteCloudfilesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Cloudfiles logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/cloudfiles/describe.go b/pkg/commands/logging/cloudfiles/describe.go index 8cb67b9a5..7d0b8ff13 100644 --- a/pkg/commands/logging/cloudfiles/describe.go +++ b/pkg/commands/logging/cloudfiles/describe.go @@ -3,12 +3,12 @@ package cloudfiles import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Cloudfiles logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetCloudfilesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Cloudfiles logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/cloudfiles/list.go b/pkg/commands/logging/cloudfiles/list.go index 2cca155f7..f9b9e793d 100644 --- a/pkg/commands/logging/cloudfiles/list.go +++ b/pkg/commands/logging/cloudfiles/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Cloudfiles logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListCloudfilesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Cloudfiles endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/cloudfiles/update.go b/pkg/commands/logging/cloudfiles/update.go index e547ccde5..30aeff046 100644 --- a/pkg/commands/logging/cloudfiles/update.go +++ b/pkg/commands/logging/cloudfiles/update.go @@ -44,12 +44,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Cloudfiles logging endpoint on a Fastly service version") @@ -85,7 +84,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -179,7 +178,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/datadog/create.go b/pkg/commands/logging/datadog/create.go index 781b64240..2e5c8e7ff 100644 --- a/pkg/commands/logging/datadog/create.go +++ b/pkg/commands/logging/datadog/create.go @@ -3,13 +3,14 @@ package datadog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Datadog logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Datadog logging endpoint on a Fastly service version").Alias("add") @@ -65,7 +65,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -118,7 +118,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/datadog/datadog_integration_test.go b/pkg/commands/logging/datadog/datadog_integration_test.go index bce6272b1..0edbdd848 100644 --- a/pkg/commands/logging/datadog/datadog_integration_test.go +++ b/pkg/commands/logging/datadog/datadog_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestDatadogCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestDatadogList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestDatadogDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestDatadogUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestDatadogDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/datadog/delete.go b/pkg/commands/logging/datadog/delete.go index 29435ba77..d53570cbe 100644 --- a/pkg/commands/logging/datadog/delete.go +++ b/pkg/commands/logging/datadog/delete.go @@ -3,18 +3,17 @@ package datadog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Datadog logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteDatadogInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Datadog logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/datadog/describe.go b/pkg/commands/logging/datadog/describe.go index bf0700611..716fdbcef 100644 --- a/pkg/commands/logging/datadog/describe.go +++ b/pkg/commands/logging/datadog/describe.go @@ -3,12 +3,12 @@ package datadog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Datadog logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetDatadogInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Datadog logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/datadog/list.go b/pkg/commands/logging/datadog/list.go index 789a6045c..c32a06142 100644 --- a/pkg/commands/logging/datadog/list.go +++ b/pkg/commands/logging/datadog/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Datadog logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListDatadogInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Datadog endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/datadog/update.go b/pkg/commands/logging/datadog/update.go index 445d4ad70..631b3de2e 100644 --- a/pkg/commands/logging/datadog/update.go +++ b/pkg/commands/logging/datadog/update.go @@ -3,13 +3,14 @@ package datadog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Datadog logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Datadog logging endpoint on a Fastly service version") @@ -67,7 +67,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -123,7 +123,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/digitalocean/create.go b/pkg/commands/logging/digitalocean/create.go index 2d007a388..94ed0b83f 100644 --- a/pkg/commands/logging/digitalocean/create.go +++ b/pkg/commands/logging/digitalocean/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a DigitalOcean Spaces logging endpoint. @@ -43,12 +44,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a DigitalOcean Spaces logging endpoint on a Fastly service version").Alias("add") @@ -83,7 +83,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -177,7 +177,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/digitalocean/delete.go b/pkg/commands/logging/digitalocean/delete.go index 3b2f628eb..67ede2c56 100644 --- a/pkg/commands/logging/digitalocean/delete.go +++ b/pkg/commands/logging/digitalocean/delete.go @@ -3,18 +3,17 @@ package digitalocean import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a DigitalOcean Spaces logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteDigitalOceanInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a DigitalOcean Spaces logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/digitalocean/describe.go b/pkg/commands/logging/digitalocean/describe.go index 6037e9f81..b2e5d201a 100644 --- a/pkg/commands/logging/digitalocean/describe.go +++ b/pkg/commands/logging/digitalocean/describe.go @@ -3,12 +3,12 @@ package digitalocean import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a DigitalOcean Spaces logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetDigitalOceanInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a DigitalOcean Spaces logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/digitalocean/digitalocean_integration_test.go b/pkg/commands/logging/digitalocean/digitalocean_integration_test.go index 14788c45a..8cc3220ba 100644 --- a/pkg/commands/logging/digitalocean/digitalocean_integration_test.go +++ b/pkg/commands/logging/digitalocean/digitalocean_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestDigitalOceanCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestDigitalOceanList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestDigitalOceanDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestDigitalOceanUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestDigitalOceanDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/digitalocean/list.go b/pkg/commands/logging/digitalocean/list.go index c7808374d..eb8e8df06 100644 --- a/pkg/commands/logging/digitalocean/list.go +++ b/pkg/commands/logging/digitalocean/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list DigitalOcean Spaces logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListDigitalOceansInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List DigitalOcean Spaces logging endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/digitalocean/update.go b/pkg/commands/logging/digitalocean/update.go index e671b4688..f55c4d18d 100644 --- a/pkg/commands/logging/digitalocean/update.go +++ b/pkg/commands/logging/digitalocean/update.go @@ -3,13 +3,14 @@ package digitalocean import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a DigitalOcean Spaces logging endpoint. @@ -43,12 +44,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a DigitalOcean Spaces logging endpoint on a Fastly service version") @@ -84,7 +84,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -178,7 +178,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/elasticsearch/create.go b/pkg/commands/logging/elasticsearch/create.go index 36dbeb140..0b570b0b3 100644 --- a/pkg/commands/logging/elasticsearch/create.go +++ b/pkg/commands/logging/elasticsearch/create.go @@ -3,13 +3,14 @@ package elasticsearch import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an Elasticsearch logging endpoint. @@ -42,12 +43,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an Elasticsearch logging endpoint on a Fastly service version").Alias("add") @@ -76,7 +76,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -169,7 +169,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/elasticsearch/delete.go b/pkg/commands/logging/elasticsearch/delete.go index bfdba2960..5dd751e25 100644 --- a/pkg/commands/logging/elasticsearch/delete.go +++ b/pkg/commands/logging/elasticsearch/delete.go @@ -3,18 +3,17 @@ package elasticsearch import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an Elasticsearch logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteElasticsearchInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an Elasticsearch logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/elasticsearch/describe.go b/pkg/commands/logging/elasticsearch/describe.go index d90ee52e3..cc72397f1 100644 --- a/pkg/commands/logging/elasticsearch/describe.go +++ b/pkg/commands/logging/elasticsearch/describe.go @@ -3,12 +3,12 @@ package elasticsearch import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an Elasticsearch logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetElasticsearchInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an Elasticsearch logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/elasticsearch/elasticsearch_integration_test.go b/pkg/commands/logging/elasticsearch/elasticsearch_integration_test.go index 097f76681..690898fdd 100644 --- a/pkg/commands/logging/elasticsearch/elasticsearch_integration_test.go +++ b/pkg/commands/logging/elasticsearch/elasticsearch_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestElasticsearchCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestElasticsearchList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestElasticsearchDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestElasticsearchUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestElasticsearchDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/elasticsearch/list.go b/pkg/commands/logging/elasticsearch/list.go index a2caaec94..20af9da99 100644 --- a/pkg/commands/logging/elasticsearch/list.go +++ b/pkg/commands/logging/elasticsearch/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Elasticsearch logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListElasticsearchInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Elasticsearch endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/elasticsearch/update.go b/pkg/commands/logging/elasticsearch/update.go index bf804f303..360311590 100644 --- a/pkg/commands/logging/elasticsearch/update.go +++ b/pkg/commands/logging/elasticsearch/update.go @@ -3,13 +3,14 @@ package elasticsearch import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an Elasticsearch logging endpoint. @@ -43,12 +44,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an Elasticsearch logging endpoint on a Fastly service version") @@ -78,7 +78,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -175,7 +175,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/ftp/create.go b/pkg/commands/logging/ftp/create.go index c9409d87d..927e2ee86 100644 --- a/pkg/commands/logging/ftp/create.go +++ b/pkg/commands/logging/ftp/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an FTP logging endpoint. @@ -41,12 +42,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an FTP logging endpoint on a Fastly service version").Alias("add") @@ -79,7 +79,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -165,7 +165,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/ftp/delete.go b/pkg/commands/logging/ftp/delete.go index b623ade23..871eb1b2d 100644 --- a/pkg/commands/logging/ftp/delete.go +++ b/pkg/commands/logging/ftp/delete.go @@ -3,18 +3,17 @@ package ftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an FTP logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteFTPInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an FTP logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/ftp/describe.go b/pkg/commands/logging/ftp/describe.go index 7d7cd9c7f..5ddcedc0c 100644 --- a/pkg/commands/logging/ftp/describe.go +++ b/pkg/commands/logging/ftp/describe.go @@ -3,12 +3,12 @@ package ftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an FTP logging endpoint. @@ -16,26 +16,24 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetFTPInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an FTP logging endpoint on a Fastly service version").Alias("get") c.RegisterFlagBool(c.JSONFlag()) // --json c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -63,7 +61,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/ftp/ftp_integration_test.go b/pkg/commands/logging/ftp/ftp_integration_test.go index 9c723dce4..fb3c3cde1 100644 --- a/pkg/commands/logging/ftp/ftp_integration_test.go +++ b/pkg/commands/logging/ftp/ftp_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestFTPCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestFTPList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestFTPDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestFTPUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestFTPDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/ftp/list.go b/pkg/commands/logging/ftp/list.go index 4e0d4aa21..fe52ed62e 100644 --- a/pkg/commands/logging/ftp/list.go +++ b/pkg/commands/logging/ftp/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list FTP logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListFTPsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List FTP endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/ftp/update.go b/pkg/commands/logging/ftp/update.go index 692095bfd..a3b4e77d7 100644 --- a/pkg/commands/logging/ftp/update.go +++ b/pkg/commands/logging/ftp/update.go @@ -3,13 +3,14 @@ package ftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an FTP logging endpoint. @@ -42,12 +43,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an FTP logging endpoint on a Fastly service version") @@ -81,7 +81,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -172,7 +172,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/gcs/create.go b/pkg/commands/logging/gcs/create.go index 8a2c974da..51a5f31fb 100644 --- a/pkg/commands/logging/gcs/create.go +++ b/pkg/commands/logging/gcs/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a GCS logging endpoint. @@ -42,12 +43,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a GCS logging endpoint on a Fastly service version").Alias("add") @@ -80,7 +80,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -161,7 +161,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/gcs/delete.go b/pkg/commands/logging/gcs/delete.go index 6120652e6..b545ebbc1 100644 --- a/pkg/commands/logging/gcs/delete.go +++ b/pkg/commands/logging/gcs/delete.go @@ -3,18 +3,17 @@ package gcs import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a GCS logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteGCSInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a GCS logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/gcs/describe.go b/pkg/commands/logging/gcs/describe.go index d7d03c7ed..97a938fab 100644 --- a/pkg/commands/logging/gcs/describe.go +++ b/pkg/commands/logging/gcs/describe.go @@ -3,12 +3,12 @@ package gcs import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a GCS logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetGCSInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a GCS logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/gcs/gcs_integration_test.go b/pkg/commands/logging/gcs/gcs_integration_test.go index 3059abbf4..ccac331a4 100644 --- a/pkg/commands/logging/gcs/gcs_integration_test.go +++ b/pkg/commands/logging/gcs/gcs_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestGCSCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestGCSList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestGCSDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestGCSUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestGCSDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/gcs/list.go b/pkg/commands/logging/gcs/list.go index 12db8738d..e1b1fabc7 100644 --- a/pkg/commands/logging/gcs/list.go +++ b/pkg/commands/logging/gcs/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list GCS logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListGCSsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List GCS endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/gcs/update.go b/pkg/commands/logging/gcs/update.go index 0fd229a86..c62a04336 100644 --- a/pkg/commands/logging/gcs/update.go +++ b/pkg/commands/logging/gcs/update.go @@ -3,13 +3,14 @@ package gcs import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a GCS logging endpoint. @@ -42,12 +43,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a GCS logging endpoint on a Fastly service version") @@ -81,7 +81,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -157,7 +157,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/googlepubsub/create.go b/pkg/commands/logging/googlepubsub/create.go index 08b1bc2dc..6f90b4322 100644 --- a/pkg/commands/logging/googlepubsub/create.go +++ b/pkg/commands/logging/googlepubsub/create.go @@ -3,13 +3,14 @@ package googlepubsub import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Google Cloud Pub/Sub logging endpoint. @@ -36,12 +37,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Google Cloud Pub/Sub logging endpoint on a Fastly service version").Alias("add") @@ -69,7 +69,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -129,7 +129,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/googlepubsub/delete.go b/pkg/commands/logging/googlepubsub/delete.go index a684adf57..d2342240d 100644 --- a/pkg/commands/logging/googlepubsub/delete.go +++ b/pkg/commands/logging/googlepubsub/delete.go @@ -3,18 +3,17 @@ package googlepubsub import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Google Cloud Pub/Sub logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeletePubsubInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Google Cloud Pub/Sub logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/googlepubsub/describe.go b/pkg/commands/logging/googlepubsub/describe.go index a6d93e3bc..011e2267f 100644 --- a/pkg/commands/logging/googlepubsub/describe.go +++ b/pkg/commands/logging/googlepubsub/describe.go @@ -3,12 +3,12 @@ package googlepubsub import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Google Cloud Pub/Sub logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetPubsubInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Google Cloud Pub/Sub logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/googlepubsub/googlepubsub_integration_test.go b/pkg/commands/logging/googlepubsub/googlepubsub_integration_test.go index f830da83b..b151699e9 100644 --- a/pkg/commands/logging/googlepubsub/googlepubsub_integration_test.go +++ b/pkg/commands/logging/googlepubsub/googlepubsub_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestGooglePubSubCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestGooglePubSubList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestGooglePubSubDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestGooglePubSubUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestGooglePubSubDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/googlepubsub/list.go b/pkg/commands/logging/googlepubsub/list.go index ca132487d..a9ae5b661 100644 --- a/pkg/commands/logging/googlepubsub/list.go +++ b/pkg/commands/logging/googlepubsub/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Google Cloud Pub/Sub logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListPubsubsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Google Cloud Pub/Sub endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/googlepubsub/update.go b/pkg/commands/logging/googlepubsub/update.go index a9c1a5051..106ed3f7f 100644 --- a/pkg/commands/logging/googlepubsub/update.go +++ b/pkg/commands/logging/googlepubsub/update.go @@ -3,13 +3,14 @@ package googlepubsub import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Google Cloud Pub/Sub logging endpoint. @@ -37,12 +38,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Google Cloud Pub/Sub logging endpoint on a Fastly service version") @@ -71,7 +71,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -132,7 +132,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/heroku/create.go b/pkg/commands/logging/heroku/create.go index 92e485e2c..c23505289 100644 --- a/pkg/commands/logging/heroku/create.go +++ b/pkg/commands/logging/heroku/create.go @@ -3,13 +3,14 @@ package heroku import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Heroku logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Heroku logging endpoint on a Fastly service version").Alias("add") @@ -64,7 +64,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -117,7 +117,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/heroku/delete.go b/pkg/commands/logging/heroku/delete.go index 5c50640d2..0572798f8 100644 --- a/pkg/commands/logging/heroku/delete.go +++ b/pkg/commands/logging/heroku/delete.go @@ -3,18 +3,17 @@ package heroku import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Heroku logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteHerokuInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Heroku logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/heroku/describe.go b/pkg/commands/logging/heroku/describe.go index 938d72599..8c49da15b 100644 --- a/pkg/commands/logging/heroku/describe.go +++ b/pkg/commands/logging/heroku/describe.go @@ -3,12 +3,12 @@ package heroku import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Heroku logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetHerokuInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Heroku logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/heroku/heroku_integration_test.go b/pkg/commands/logging/heroku/heroku_integration_test.go index 9d2f2646e..0de173704 100644 --- a/pkg/commands/logging/heroku/heroku_integration_test.go +++ b/pkg/commands/logging/heroku/heroku_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestHerokuCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestHerokuList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestHerokuDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestHerokuUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestHerokuDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/heroku/list.go b/pkg/commands/logging/heroku/list.go index dd8825882..e4345164f 100644 --- a/pkg/commands/logging/heroku/list.go +++ b/pkg/commands/logging/heroku/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Heroku logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListHerokusInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Heroku endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/heroku/update.go b/pkg/commands/logging/heroku/update.go index dbe09a5d6..d46c0b406 100644 --- a/pkg/commands/logging/heroku/update.go +++ b/pkg/commands/logging/heroku/update.go @@ -3,13 +3,14 @@ package heroku import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Heroku logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Heroku logging endpoint on a Fastly service version") @@ -66,7 +66,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -123,7 +123,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/honeycomb/create.go b/pkg/commands/logging/honeycomb/create.go index a018b62e8..93ff7431b 100644 --- a/pkg/commands/logging/honeycomb/create.go +++ b/pkg/commands/logging/honeycomb/create.go @@ -3,13 +3,14 @@ package honeycomb import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Honeycomb logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Honeycomb logging endpoint on a Fastly service version").Alias("add") @@ -65,7 +65,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -117,7 +117,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/honeycomb/delete.go b/pkg/commands/logging/honeycomb/delete.go index 9f93b5279..9f6fe7672 100644 --- a/pkg/commands/logging/honeycomb/delete.go +++ b/pkg/commands/logging/honeycomb/delete.go @@ -3,18 +3,17 @@ package honeycomb import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Honeycomb logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteHoneycombInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Honeycomb logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/honeycomb/describe.go b/pkg/commands/logging/honeycomb/describe.go index 554fe1779..9a6b79e63 100644 --- a/pkg/commands/logging/honeycomb/describe.go +++ b/pkg/commands/logging/honeycomb/describe.go @@ -3,12 +3,12 @@ package honeycomb import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Honeycomb logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetHoneycombInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Honeycomb logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/honeycomb/honeycomb_integration_test.go b/pkg/commands/logging/honeycomb/honeycomb_integration_test.go index 5e83d4202..d7ac97ff3 100644 --- a/pkg/commands/logging/honeycomb/honeycomb_integration_test.go +++ b/pkg/commands/logging/honeycomb/honeycomb_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestHoneycombCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestHoneycombList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestHoneycombDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestHoneycombUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestHoneycombDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/honeycomb/list.go b/pkg/commands/logging/honeycomb/list.go index 8af9bd835..508594f94 100644 --- a/pkg/commands/logging/honeycomb/list.go +++ b/pkg/commands/logging/honeycomb/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Honeycomb logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListHoneycombsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Honeycomb endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/honeycomb/update.go b/pkg/commands/logging/honeycomb/update.go index 3fe7905bd..7dd9550d8 100644 --- a/pkg/commands/logging/honeycomb/update.go +++ b/pkg/commands/logging/honeycomb/update.go @@ -3,13 +3,14 @@ package honeycomb import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Honeycomb logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Honeycomb logging endpoint on a Fastly service version") @@ -67,7 +67,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -123,7 +123,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/https/create.go b/pkg/commands/logging/https/create.go index fbb5c2a1f..5afb0a62d 100644 --- a/pkg/commands/logging/https/create.go +++ b/pkg/commands/logging/https/create.go @@ -3,13 +3,14 @@ package https import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an HTTPS logging endpoint. @@ -44,12 +45,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an HTTPS logging endpoint on a Fastly service version").Alias("add") @@ -82,7 +82,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -184,7 +184,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/https/delete.go b/pkg/commands/logging/https/delete.go index 8e9fcb484..052d0d7b4 100644 --- a/pkg/commands/logging/https/delete.go +++ b/pkg/commands/logging/https/delete.go @@ -3,18 +3,17 @@ package https import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an HTTPS logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteHTTPSInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an HTTPS logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/https/describe.go b/pkg/commands/logging/https/describe.go index 7b05200d5..b378fd7d6 100644 --- a/pkg/commands/logging/https/describe.go +++ b/pkg/commands/logging/https/describe.go @@ -3,12 +3,12 @@ package https import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an HTTPS logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetHTTPSInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an HTTPS logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/https/https_integration_test.go b/pkg/commands/logging/https/https_integration_test.go index 04375291c..960d58ede 100644 --- a/pkg/commands/logging/https/https_integration_test.go +++ b/pkg/commands/logging/https/https_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestHTTPSCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestHTTPSList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestHTTPSDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestHTTPSUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestHTTPSDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/https/list.go b/pkg/commands/logging/https/list.go index 8be2ca602..5af3ec9d7 100644 --- a/pkg/commands/logging/https/list.go +++ b/pkg/commands/logging/https/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list HTTPS logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListHTTPSInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List HTTPS endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/https/update.go b/pkg/commands/logging/https/update.go index bb9edbc80..1cbb5aab7 100644 --- a/pkg/commands/logging/https/update.go +++ b/pkg/commands/logging/https/update.go @@ -3,13 +3,14 @@ package https import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an HTTPS logging endpoint. @@ -45,12 +46,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an HTTPS logging endpoint on a Fastly service version") @@ -84,7 +84,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -189,7 +189,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/kafka/create.go b/pkg/commands/logging/kafka/create.go index 6fcf2b856..f9d3a387b 100644 --- a/pkg/commands/logging/kafka/create.go +++ b/pkg/commands/logging/kafka/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Kafka logging endpoint. @@ -47,12 +48,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Kafka logging endpoint on a Fastly service version").Alias("add") @@ -84,7 +84,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -200,7 +200,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/kafka/delete.go b/pkg/commands/logging/kafka/delete.go index bdf8f0a43..a5a4d6050 100644 --- a/pkg/commands/logging/kafka/delete.go +++ b/pkg/commands/logging/kafka/delete.go @@ -3,18 +3,17 @@ package kafka import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Kafka logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteKafkaInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Kafka logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kafka/describe.go b/pkg/commands/logging/kafka/describe.go index d61c23094..511680e05 100644 --- a/pkg/commands/logging/kafka/describe.go +++ b/pkg/commands/logging/kafka/describe.go @@ -3,12 +3,12 @@ package kafka import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Kafka logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetKafkaInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Kafka logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kafka/kafka_integration_test.go b/pkg/commands/logging/kafka/kafka_integration_test.go index 8a01f7b18..2c2e4793e 100644 --- a/pkg/commands/logging/kafka/kafka_integration_test.go +++ b/pkg/commands/logging/kafka/kafka_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestKafkaCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestKafkaList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestKafkaDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -219,8 +220,8 @@ func TestKafkaUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -266,8 +267,8 @@ func TestKafkaDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -331,9 +332,9 @@ func listKafkasOK(i *fastly.ListKafkasInput) ([]*fastly.Kafka, error) { FormatVersion: 2, ParseLogKeyvals: false, RequestMaxBytes: 0, - AuthMethod: "", - User: "", - Password: "", + AuthMethod: "plain", + User: "user", + Password: "password", }, { ServiceID: i.ServiceID, @@ -354,9 +355,9 @@ func listKafkasOK(i *fastly.ListKafkasInput) ([]*fastly.Kafka, error) { FormatVersion: 2, ParseLogKeyvals: false, RequestMaxBytes: 0, - AuthMethod: "", - User: "", - Password: "", + AuthMethod: "plain", + User: "user", + Password: "password", }, }, nil } @@ -397,9 +398,9 @@ Version: 1 Placement: none Parse log key-values: false Max batch size: 0 - SASL authentication method: - SASL authentication username: - SASL authentication password: + SASL authentication method: plain + SASL authentication username: user + SASL authentication password: password Kafka 2/2 Service ID: 123 Version: 1 @@ -419,10 +420,10 @@ Version: 1 Placement: none Parse log key-values: false Max batch size: 0 - SASL authentication method: - SASL authentication username: - SASL authentication password: -`) + " \n\n" + SASL authentication method: plain + SASL authentication username: user + SASL authentication password: password + `) + "\n\n" func getKafkaOK(i *fastly.GetKafkaInput) (*fastly.Kafka, error) { return &fastly.Kafka{ diff --git a/pkg/commands/logging/kafka/list.go b/pkg/commands/logging/kafka/list.go index 9b21cdffc..3c9b6c0b5 100644 --- a/pkg/commands/logging/kafka/list.go +++ b/pkg/commands/logging/kafka/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Kafka logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListKafkasInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Kafka endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kafka/update.go b/pkg/commands/logging/kafka/update.go index 522eed61f..e703bd8e6 100644 --- a/pkg/commands/logging/kafka/update.go +++ b/pkg/commands/logging/kafka/update.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Kafka logging endpoint. @@ -49,12 +50,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Kafka logging endpoint on a Fastly service version") @@ -87,7 +87,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -213,7 +213,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/kinesis/create.go b/pkg/commands/logging/kinesis/create.go index 7e754046d..1b006ad6c 100644 --- a/pkg/commands/logging/kinesis/create.go +++ b/pkg/commands/logging/kinesis/create.go @@ -41,12 +41,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an Amazon Kinesis logging endpoint on a Fastly service version").Alias("add") @@ -78,7 +77,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -161,7 +160,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/kinesis/delete.go b/pkg/commands/logging/kinesis/delete.go index b61cc8653..1a1f44737 100644 --- a/pkg/commands/logging/kinesis/delete.go +++ b/pkg/commands/logging/kinesis/delete.go @@ -3,18 +3,17 @@ package kinesis import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an Amazon Kinesis logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteKinesisInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Kinesis logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -66,7 +64,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kinesis/describe.go b/pkg/commands/logging/kinesis/describe.go index 4bdf3372a..fb2390410 100644 --- a/pkg/commands/logging/kinesis/describe.go +++ b/pkg/commands/logging/kinesis/describe.go @@ -3,12 +3,12 @@ package kinesis import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an Amazon Kinesis logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetKinesisInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Kinesis logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kinesis/kinesis_integration_test.go b/pkg/commands/logging/kinesis/kinesis_integration_test.go index f44415567..b01bcfb83 100644 --- a/pkg/commands/logging/kinesis/kinesis_integration_test.go +++ b/pkg/commands/logging/kinesis/kinesis_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -87,8 +88,8 @@ func TestKinesisCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -160,8 +161,8 @@ func TestKinesisList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -205,8 +206,8 @@ func TestKinesisDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -252,8 +253,8 @@ func TestKinesisUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -299,8 +300,8 @@ func TestKinesisDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/kinesis/list.go b/pkg/commands/logging/kinesis/list.go index a9fdf5412..b5d71a9ff 100644 --- a/pkg/commands/logging/kinesis/list.go +++ b/pkg/commands/logging/kinesis/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Amazon Kinesis logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListKinesisInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Kinesis endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/kinesis/update.go b/pkg/commands/logging/kinesis/update.go index 10515ada3..563f8bbb1 100644 --- a/pkg/commands/logging/kinesis/update.go +++ b/pkg/commands/logging/kinesis/update.go @@ -3,13 +3,14 @@ package kinesis import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an Amazon Kinesis logging endpoint. @@ -37,12 +38,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Kinesis logging endpoint on a Fastly service version") @@ -72,7 +72,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -141,7 +141,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/loggly/create.go b/pkg/commands/logging/loggly/create.go index d3808c3e8..fe457d98b 100644 --- a/pkg/commands/logging/loggly/create.go +++ b/pkg/commands/logging/loggly/create.go @@ -3,13 +3,14 @@ package loggly import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Loggly logging endpoint. @@ -32,12 +33,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Loggly logging endpoint on a Fastly service version").Alias("add") @@ -63,7 +63,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -112,7 +112,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/loggly/delete.go b/pkg/commands/logging/loggly/delete.go index 6cf69c81b..956078a5f 100644 --- a/pkg/commands/logging/loggly/delete.go +++ b/pkg/commands/logging/loggly/delete.go @@ -3,18 +3,17 @@ package loggly import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Loggly logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteLogglyInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Loggly logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/loggly/describe.go b/pkg/commands/logging/loggly/describe.go index dd1aaad4f..8567fc7a5 100644 --- a/pkg/commands/logging/loggly/describe.go +++ b/pkg/commands/logging/loggly/describe.go @@ -3,12 +3,12 @@ package loggly import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Loggly logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetLogglyInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Loggly logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/loggly/list.go b/pkg/commands/logging/loggly/list.go index a26456c63..382af5e34 100644 --- a/pkg/commands/logging/loggly/list.go +++ b/pkg/commands/logging/loggly/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Loggly logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListLogglyInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Loggly endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/loggly/loggly_integration_test.go b/pkg/commands/logging/loggly/loggly_integration_test.go index 6f63e3843..403f61b8f 100644 --- a/pkg/commands/logging/loggly/loggly_integration_test.go +++ b/pkg/commands/logging/loggly/loggly_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestLogglyCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestLogglyList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestLogglyDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestLogglyUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestLogglyDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/loggly/update.go b/pkg/commands/logging/loggly/update.go index c6d2f9e3c..3ca8fa8c6 100644 --- a/pkg/commands/logging/loggly/update.go +++ b/pkg/commands/logging/loggly/update.go @@ -3,13 +3,14 @@ package loggly import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Loggly logging endpoint. @@ -33,12 +34,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Loggly logging endpoint on a Fastly service version") @@ -65,7 +65,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -117,7 +117,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/logshuttle/create.go b/pkg/commands/logging/logshuttle/create.go index e37fdd8ef..c825f472b 100644 --- a/pkg/commands/logging/logshuttle/create.go +++ b/pkg/commands/logging/logshuttle/create.go @@ -3,13 +3,14 @@ package logshuttle import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Logshuttle logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Logshuttle logging endpoint on a Fastly service version").Alias("add") @@ -64,7 +64,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -117,7 +117,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/logshuttle/delete.go b/pkg/commands/logging/logshuttle/delete.go index 824b46807..ab434a3d7 100644 --- a/pkg/commands/logging/logshuttle/delete.go +++ b/pkg/commands/logging/logshuttle/delete.go @@ -3,18 +3,17 @@ package logshuttle import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Logshuttle logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteLogshuttleInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Logshuttle logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/logshuttle/describe.go b/pkg/commands/logging/logshuttle/describe.go index d24ee1527..aeaf3669e 100644 --- a/pkg/commands/logging/logshuttle/describe.go +++ b/pkg/commands/logging/logshuttle/describe.go @@ -3,12 +3,12 @@ package logshuttle import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Logshuttle logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetLogshuttleInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Logshuttle logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/logshuttle/list.go b/pkg/commands/logging/logshuttle/list.go index f834ddb9f..bb9db397d 100644 --- a/pkg/commands/logging/logshuttle/list.go +++ b/pkg/commands/logging/logshuttle/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Logshuttle logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListLogshuttlesInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Logshuttle endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/logshuttle/logshuttle_integration_test.go b/pkg/commands/logging/logshuttle/logshuttle_integration_test.go index 2b2bc1cf0..77984e463 100644 --- a/pkg/commands/logging/logshuttle/logshuttle_integration_test.go +++ b/pkg/commands/logging/logshuttle/logshuttle_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestLogshuttleCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestLogshuttleList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestLogshuttleDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestLogshuttleUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestLogshuttleDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/logshuttle/update.go b/pkg/commands/logging/logshuttle/update.go index 3641661f8..5578e5c50 100644 --- a/pkg/commands/logging/logshuttle/update.go +++ b/pkg/commands/logging/logshuttle/update.go @@ -3,13 +3,14 @@ package logshuttle import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Logshuttle logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Logshuttle logging endpoint on a Fastly service version") @@ -66,7 +66,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -124,7 +124,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/newrelic/create.go b/pkg/commands/logging/newrelic/create.go index 823e1324f..c6482ae12 100644 --- a/pkg/commands/logging/newrelic/create.go +++ b/pkg/commands/logging/newrelic/create.go @@ -3,19 +3,18 @@ package newrelic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an appropriate resource. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceName cmd.OptionalServiceNameID @@ -33,12 +32,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create an New Relic logging endpoint attached to the specified service version").Alias("add") @@ -65,7 +63,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -83,7 +81,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelic/delete.go b/pkg/commands/logging/newrelic/delete.go index f83e5b195..ad4c4115a 100644 --- a/pkg/commands/logging/newrelic/delete.go +++ b/pkg/commands/logging/newrelic/delete.go @@ -3,21 +3,20 @@ package newrelic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete the New Relic Logs logging object for a particular service and version").Alias("remove") @@ -38,7 +37,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -56,7 +55,6 @@ type DeleteCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -67,7 +65,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelic/describe.go b/pkg/commands/logging/newrelic/describe.go index 5dd422a8c..5d5bcc0d8 100644 --- a/pkg/commands/logging/newrelic/describe.go +++ b/pkg/commands/logging/newrelic/describe.go @@ -3,21 +3,20 @@ package newrelic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the details of a New Relic Logs logging object for a particular service and version").Alias("get") @@ -35,7 +34,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -68,7 +66,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelic/list.go b/pkg/commands/logging/newrelic/list.go index 66ddf999a..d66fe4077 100644 --- a/pkg/commands/logging/newrelic/list.go +++ b/pkg/commands/logging/newrelic/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List all of the New Relic Logs logging objects for a particular service and version") @@ -35,7 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelic/newrelic_test.go b/pkg/commands/logging/newrelic/newrelic_test.go index 6799e9ce0..c5e38deb9 100644 --- a/pkg/commands/logging/newrelic/newrelic_test.go +++ b/pkg/commands/logging/newrelic/newrelic_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -76,8 +77,8 @@ func TestNewRelicCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -154,8 +155,8 @@ func TestNewRelicDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -219,8 +220,8 @@ func TestNewRelicDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -288,8 +289,8 @@ func TestNewRelicList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -374,8 +375,8 @@ func TestNewRelicUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/logging/newrelic/update.go b/pkg/commands/logging/newrelic/update.go index ce48c0d28..6abe4e2cc 100644 --- a/pkg/commands/logging/newrelic/update.go +++ b/pkg/commands/logging/newrelic/update.go @@ -4,13 +4,13 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an appropriate resource. @@ -25,7 +25,6 @@ type UpdateCommand struct { format cmd.OptionalString formatVersion cmd.OptionalInt key cmd.OptionalString - manifest manifest.Data newName cmd.OptionalString placement cmd.OptionalString region cmd.OptionalString @@ -33,12 +32,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a New Relic Logs logging object for a particular service and version") @@ -66,7 +64,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -84,7 +82,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelicotlp/create.go b/pkg/commands/logging/newrelicotlp/create.go index cc19c9a8e..76f7bfaef 100644 --- a/pkg/commands/logging/newrelicotlp/create.go +++ b/pkg/commands/logging/newrelicotlp/create.go @@ -3,19 +3,18 @@ package newrelicotlp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an appropriate resource. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceName cmd.OptionalServiceNameID @@ -34,12 +33,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create an New Relic logging endpoint attached to the specified service version").Alias("add") @@ -67,7 +65,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -85,7 +83,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelicotlp/delete.go b/pkg/commands/logging/newrelicotlp/delete.go index c591be1fb..1867b87f3 100644 --- a/pkg/commands/logging/newrelicotlp/delete.go +++ b/pkg/commands/logging/newrelicotlp/delete.go @@ -3,21 +3,20 @@ package newrelicotlp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete the New Relic OTLP Logs logging object for a particular service and version").Alias("remove") @@ -38,7 +37,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -56,7 +55,6 @@ type DeleteCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -67,7 +65,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelicotlp/describe.go b/pkg/commands/logging/newrelicotlp/describe.go index ad16d99d5..4831ceea6 100644 --- a/pkg/commands/logging/newrelicotlp/describe.go +++ b/pkg/commands/logging/newrelicotlp/describe.go @@ -3,21 +3,20 @@ package newrelicotlp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the details of a New Relic OTLP Logs logging object for a particular service and version").Alias("get") @@ -35,7 +34,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -68,7 +66,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelicotlp/list.go b/pkg/commands/logging/newrelicotlp/list.go index e580b293b..205a75e2e 100644 --- a/pkg/commands/logging/newrelicotlp/list.go +++ b/pkg/commands/logging/newrelicotlp/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List all of the New Relic OTLP Logs logging objects for a particular service and version") @@ -35,7 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go b/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go index 755397624..135fe50aa 100644 --- a/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go +++ b/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -76,8 +77,8 @@ func TestNewRelicOTLPCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -154,8 +155,8 @@ func TestNewRelicOTLPDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -219,8 +220,8 @@ func TestNewRelicDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -288,8 +289,8 @@ func TestNewRelicList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -374,8 +375,8 @@ func TestNewRelicUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/logging/newrelicotlp/update.go b/pkg/commands/logging/newrelicotlp/update.go index f364373b7..72e09dfdf 100644 --- a/pkg/commands/logging/newrelicotlp/update.go +++ b/pkg/commands/logging/newrelicotlp/update.go @@ -4,13 +4,13 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an appropriate resource. @@ -25,7 +25,6 @@ type UpdateCommand struct { format cmd.OptionalString formatVersion cmd.OptionalInt key cmd.OptionalString - manifest manifest.Data newName cmd.OptionalString placement cmd.OptionalString region cmd.OptionalString @@ -34,12 +33,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a New Relic Logs logging object for a particular service and version") @@ -68,7 +66,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -86,7 +84,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/openstack/create.go b/pkg/commands/logging/openstack/create.go index ec7582917..3b09ac924 100644 --- a/pkg/commands/logging/openstack/create.go +++ b/pkg/commands/logging/openstack/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an OpenStack logging endpoint. @@ -43,12 +44,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an OpenStack logging endpoint on a Fastly service version").Alias("add") @@ -82,7 +82,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -176,7 +176,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/openstack/delete.go b/pkg/commands/logging/openstack/delete.go index c181d7142..2aad45bb2 100644 --- a/pkg/commands/logging/openstack/delete.go +++ b/pkg/commands/logging/openstack/delete.go @@ -3,18 +3,17 @@ package openstack import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an OpenStack logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteOpenstackInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an OpenStack logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/openstack/describe.go b/pkg/commands/logging/openstack/describe.go index ed95f271a..5f5c79d63 100644 --- a/pkg/commands/logging/openstack/describe.go +++ b/pkg/commands/logging/openstack/describe.go @@ -3,12 +3,12 @@ package openstack import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an OpenStack logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetOpenstackInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an OpenStack logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/openstack/list.go b/pkg/commands/logging/openstack/list.go index 12f145140..f31be5e56 100644 --- a/pkg/commands/logging/openstack/list.go +++ b/pkg/commands/logging/openstack/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list OpenStack logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListOpenstackInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List OpenStack logging endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/openstack/openstack_integration_test.go b/pkg/commands/logging/openstack/openstack_integration_test.go index e61061a6d..309356b44 100644 --- a/pkg/commands/logging/openstack/openstack_integration_test.go +++ b/pkg/commands/logging/openstack/openstack_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestOpenstackCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestOpenstackList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestOpenstackDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestOpenstackUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestOpenstackDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/openstack/update.go b/pkg/commands/logging/openstack/update.go index d342d314e..6e3bce1bc 100644 --- a/pkg/commands/logging/openstack/update.go +++ b/pkg/commands/logging/openstack/update.go @@ -3,13 +3,14 @@ package openstack import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an OpenStack logging endpoint. @@ -43,12 +44,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an OpenStack logging endpoint on a Fastly service version") @@ -82,7 +82,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -179,7 +179,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/papertrail/create.go b/pkg/commands/logging/papertrail/create.go index c0c72a10a..ed54e2e53 100644 --- a/pkg/commands/logging/papertrail/create.go +++ b/pkg/commands/logging/papertrail/create.go @@ -3,13 +3,14 @@ package papertrail import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Papertrail logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Papertrail logging endpoint on a Fastly service version").Alias("add") @@ -65,7 +65,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -118,7 +118,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/papertrail/delete.go b/pkg/commands/logging/papertrail/delete.go index a6254aa8c..664905f45 100644 --- a/pkg/commands/logging/papertrail/delete.go +++ b/pkg/commands/logging/papertrail/delete.go @@ -3,18 +3,17 @@ package papertrail import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Papertrail logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeletePapertrailInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Papertrail logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/papertrail/describe.go b/pkg/commands/logging/papertrail/describe.go index 153f8d962..a9a51c12d 100644 --- a/pkg/commands/logging/papertrail/describe.go +++ b/pkg/commands/logging/papertrail/describe.go @@ -3,12 +3,12 @@ package papertrail import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Papertrail logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetPapertrailInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Papertrail logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/papertrail/list.go b/pkg/commands/logging/papertrail/list.go index 3c63dc779..67bade01e 100644 --- a/pkg/commands/logging/papertrail/list.go +++ b/pkg/commands/logging/papertrail/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Papertrail logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListPapertrailsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Papertrail endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/papertrail/papertrail_integration_test.go b/pkg/commands/logging/papertrail/papertrail_integration_test.go index 2e153eb59..11c2c772d 100644 --- a/pkg/commands/logging/papertrail/papertrail_integration_test.go +++ b/pkg/commands/logging/papertrail/papertrail_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestPapertrailCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestPapertrailList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestPapertrailDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestPapertrailUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestPapertrailDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/papertrail/update.go b/pkg/commands/logging/papertrail/update.go index 14d30e662..2686fab7a 100644 --- a/pkg/commands/logging/papertrail/update.go +++ b/pkg/commands/logging/papertrail/update.go @@ -3,13 +3,14 @@ package papertrail import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Papertrail logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Papertrail logging endpoint on a Fastly service version") @@ -67,7 +67,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -128,7 +128,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/s3/create.go b/pkg/commands/logging/s3/create.go index 6d51c45a5..69fe4e953 100644 --- a/pkg/commands/logging/s3/create.go +++ b/pkg/commands/logging/s3/create.go @@ -52,12 +52,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an Amazon S3 logging endpoint on a Fastly service version").Alias("add") @@ -97,7 +96,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -266,7 +265,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/s3/delete.go b/pkg/commands/logging/s3/delete.go index d299411e8..ccfc12ea2 100644 --- a/pkg/commands/logging/s3/delete.go +++ b/pkg/commands/logging/s3/delete.go @@ -3,18 +3,17 @@ package s3 import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an Amazon S3 logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteS3Input serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a S3 logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/s3/describe.go b/pkg/commands/logging/s3/describe.go index 170175f8b..f832f02b6 100644 --- a/pkg/commands/logging/s3/describe.go +++ b/pkg/commands/logging/s3/describe.go @@ -3,12 +3,12 @@ package s3 import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an Amazon S3 logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetS3Input serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a S3 logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/s3/list.go b/pkg/commands/logging/s3/list.go index 39367bdac..85586b9a5 100644 --- a/pkg/commands/logging/s3/list.go +++ b/pkg/commands/logging/s3/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Amazon S3 logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListS3sInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List S3 endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/s3/s3_integration_test.go b/pkg/commands/logging/s3/s3_integration_test.go index ef1f340e3..6c94092a5 100644 --- a/pkg/commands/logging/s3/s3_integration_test.go +++ b/pkg/commands/logging/s3/s3_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -103,8 +104,8 @@ func TestS3Create(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -176,8 +177,8 @@ func TestS3List(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -221,8 +222,8 @@ func TestS3Describe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -277,8 +278,8 @@ func TestS3Update(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -324,8 +325,8 @@ func TestS3Delete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/s3/update.go b/pkg/commands/logging/s3/update.go index 991a0e10f..9c64f4d47 100644 --- a/pkg/commands/logging/s3/update.go +++ b/pkg/commands/logging/s3/update.go @@ -3,13 +3,14 @@ package s3 import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an Amazon S3 logging endpoint. @@ -49,12 +50,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a S3 logging endpoint on a Fastly service version") @@ -95,7 +95,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -216,7 +216,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/scalyr/create.go b/pkg/commands/logging/scalyr/create.go index 77d96afe4..e1e54e517 100644 --- a/pkg/commands/logging/scalyr/create.go +++ b/pkg/commands/logging/scalyr/create.go @@ -3,13 +3,14 @@ package scalyr import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Scalyr logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Scalyr logging endpoint on a Fastly service version").Alias("add") @@ -65,7 +65,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -118,7 +118,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/scalyr/delete.go b/pkg/commands/logging/scalyr/delete.go index bd1cceb1d..90178aa63 100644 --- a/pkg/commands/logging/scalyr/delete.go +++ b/pkg/commands/logging/scalyr/delete.go @@ -3,18 +3,17 @@ package scalyr import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Scalyr logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteScalyrInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Scalyr logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/scalyr/describe.go b/pkg/commands/logging/scalyr/describe.go index 2a99bfcd1..5ec914c2b 100644 --- a/pkg/commands/logging/scalyr/describe.go +++ b/pkg/commands/logging/scalyr/describe.go @@ -3,12 +3,12 @@ package scalyr import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Scalyr logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetScalyrInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Scalyr logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/scalyr/list.go b/pkg/commands/logging/scalyr/list.go index 287602c60..9d9fb274c 100644 --- a/pkg/commands/logging/scalyr/list.go +++ b/pkg/commands/logging/scalyr/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Scalyr logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListScalyrsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Scalyr endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/scalyr/scalyr_integration_test.go b/pkg/commands/logging/scalyr/scalyr_integration_test.go index 530d6e3dc..df0669554 100644 --- a/pkg/commands/logging/scalyr/scalyr_integration_test.go +++ b/pkg/commands/logging/scalyr/scalyr_integration_test.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/app" fsterrs "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -54,8 +55,8 @@ func TestScalyrCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -127,8 +128,8 @@ func TestScalyrList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -172,8 +173,8 @@ func TestScalyrDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -219,8 +220,8 @@ func TestScalyrUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -266,8 +267,8 @@ func TestScalyrDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/scalyr/update.go b/pkg/commands/logging/scalyr/update.go index 8ffc6ded5..e5b1300cb 100644 --- a/pkg/commands/logging/scalyr/update.go +++ b/pkg/commands/logging/scalyr/update.go @@ -3,13 +3,14 @@ package scalyr import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update Scalyr logging endpoints. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Scalyr logging endpoint on a Fastly service version") @@ -67,7 +67,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -123,7 +123,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/sftp/create.go b/pkg/commands/logging/sftp/create.go index 7fbdce271..1519eaae5 100644 --- a/pkg/commands/logging/sftp/create.go +++ b/pkg/commands/logging/sftp/create.go @@ -4,13 +4,14 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create an SFTP logging endpoint. @@ -45,12 +46,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create an SFTP logging endpoint on a Fastly service version").Alias("add") @@ -85,7 +85,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -189,7 +189,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/sftp/delete.go b/pkg/commands/logging/sftp/delete.go index 125162138..da6af0aea 100644 --- a/pkg/commands/logging/sftp/delete.go +++ b/pkg/commands/logging/sftp/delete.go @@ -3,18 +3,17 @@ package sftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an SFTP logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteSFTPInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete an SFTP logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sftp/describe.go b/pkg/commands/logging/sftp/describe.go index ad28b0aa0..086329891 100644 --- a/pkg/commands/logging/sftp/describe.go +++ b/pkg/commands/logging/sftp/describe.go @@ -3,12 +3,12 @@ package sftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe an SFTP logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetSFTPInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about an SFTP logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sftp/list.go b/pkg/commands/logging/sftp/list.go index 73111719c..24d6faaa0 100644 --- a/pkg/commands/logging/sftp/list.go +++ b/pkg/commands/logging/sftp/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list SFTP logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListSFTPsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List SFTP endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sftp/sftp_integration_test.go b/pkg/commands/logging/sftp/sftp_integration_test.go index 7efeddda2..f4757fbd3 100644 --- a/pkg/commands/logging/sftp/sftp_integration_test.go +++ b/pkg/commands/logging/sftp/sftp_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,8 +54,8 @@ func TestSFTPCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -126,8 +127,8 @@ func TestSFTPList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestSFTPDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -218,8 +219,8 @@ func TestSFTPUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -265,8 +266,8 @@ func TestSFTPDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/sftp/update.go b/pkg/commands/logging/sftp/update.go index 686f26679..5d4c0c970 100644 --- a/pkg/commands/logging/sftp/update.go +++ b/pkg/commands/logging/sftp/update.go @@ -3,13 +3,14 @@ package sftp import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update an SFTP logging endpoint. @@ -45,12 +46,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update an SFTP logging endpoint on a Fastly service version") @@ -86,7 +86,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -189,7 +189,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/splunk/create.go b/pkg/commands/logging/splunk/create.go index b0bed74d6..aea271774 100644 --- a/pkg/commands/logging/splunk/create.go +++ b/pkg/commands/logging/splunk/create.go @@ -3,13 +3,14 @@ package splunk import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Splunk logging endpoint. @@ -38,12 +39,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Splunk logging endpoint on a Fastly service version").Alias("add") @@ -69,7 +69,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -143,7 +143,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/splunk/delete.go b/pkg/commands/logging/splunk/delete.go index 796c16fdc..3f8b2f3cf 100644 --- a/pkg/commands/logging/splunk/delete.go +++ b/pkg/commands/logging/splunk/delete.go @@ -3,18 +3,17 @@ package splunk import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Splunk logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteSplunkInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Splunk logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/splunk/describe.go b/pkg/commands/logging/splunk/describe.go index 1aef369e5..e99554cf4 100644 --- a/pkg/commands/logging/splunk/describe.go +++ b/pkg/commands/logging/splunk/describe.go @@ -3,12 +3,12 @@ package splunk import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Splunk logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetSplunkInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Splunk logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/splunk/list.go b/pkg/commands/logging/splunk/list.go index 81a81f7d5..a89e92f39 100644 --- a/pkg/commands/logging/splunk/list.go +++ b/pkg/commands/logging/splunk/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Splunk logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListSplunksInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Splunk endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/splunk/splunk_integration_test.go b/pkg/commands/logging/splunk/splunk_integration_test.go index 21852b186..e86768228 100644 --- a/pkg/commands/logging/splunk/splunk_integration_test.go +++ b/pkg/commands/logging/splunk/splunk_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestSplunkCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestSplunkList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestSplunkDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestSplunkUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestSplunkDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/splunk/update.go b/pkg/commands/logging/splunk/update.go index 46a4795ac..41f100bb6 100644 --- a/pkg/commands/logging/splunk/update.go +++ b/pkg/commands/logging/splunk/update.go @@ -3,13 +3,14 @@ package splunk import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Splunk logging endpoint. @@ -38,12 +39,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Splunk logging endpoint on a Fastly service version") @@ -70,7 +70,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -148,7 +148,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/sumologic/create.go b/pkg/commands/logging/sumologic/create.go index fba3c5761..6cd0d1b97 100644 --- a/pkg/commands/logging/sumologic/create.go +++ b/pkg/commands/logging/sumologic/create.go @@ -3,13 +3,14 @@ package sumologic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Sumologic logging endpoint. @@ -33,12 +34,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Sumologic logging endpoint on a Fastly service version").Alias("add") @@ -64,7 +64,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -118,7 +118,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/sumologic/delete.go b/pkg/commands/logging/sumologic/delete.go index 38aec8568..568a6f6c1 100644 --- a/pkg/commands/logging/sumologic/delete.go +++ b/pkg/commands/logging/sumologic/delete.go @@ -3,18 +3,17 @@ package sumologic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Sumologic logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteSumologicInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Sumologic logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sumologic/describe.go b/pkg/commands/logging/sumologic/describe.go index 12cdc65e4..54432c617 100644 --- a/pkg/commands/logging/sumologic/describe.go +++ b/pkg/commands/logging/sumologic/describe.go @@ -3,12 +3,12 @@ package sumologic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Sumologic logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetSumologicInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Sumologic logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sumologic/list.go b/pkg/commands/logging/sumologic/list.go index 4a088f9bf..8734beedd 100644 --- a/pkg/commands/logging/sumologic/list.go +++ b/pkg/commands/logging/sumologic/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Sumologic logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListSumologicsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Sumologic endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/sumologic/sumologic_integration_test.go b/pkg/commands/logging/sumologic/sumologic_integration_test.go index 73256ba2b..62bf6e99c 100644 --- a/pkg/commands/logging/sumologic/sumologic_integration_test.go +++ b/pkg/commands/logging/sumologic/sumologic_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestSumologicCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestSumologicList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestSumologicDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestSumologicUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestSumologicDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/logging/sumologic/update.go b/pkg/commands/logging/sumologic/update.go index cc1fcc442..ba9937ece 100644 --- a/pkg/commands/logging/sumologic/update.go +++ b/pkg/commands/logging/sumologic/update.go @@ -3,13 +3,14 @@ package sumologic import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Sumologic logging endpoint. @@ -34,12 +35,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Sumologic logging endpoint on a Fastly service version") @@ -66,7 +66,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -124,7 +124,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/syslog/create.go b/pkg/commands/logging/syslog/create.go index e53fa93b4..8819355c5 100644 --- a/pkg/commands/logging/syslog/create.go +++ b/pkg/commands/logging/syslog/create.go @@ -3,13 +3,14 @@ package syslog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a Syslog logging endpoint. @@ -40,12 +41,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("create", "Create a Syslog logging endpoint on a Fastly service version").Alias("add") @@ -68,7 +68,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) common.Format(c.CmdClause, &c.Format) @@ -159,7 +159,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logging/syslog/delete.go b/pkg/commands/logging/syslog/delete.go index 9e7f5f143..09fbab3b5 100644 --- a/pkg/commands/logging/syslog/delete.go +++ b/pkg/commands/logging/syslog/delete.go @@ -3,18 +3,17 @@ package syslog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete a Syslog logging endpoint. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteSyslogInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Syslog logging endpoint on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -65,7 +63,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/syslog/describe.go b/pkg/commands/logging/syslog/describe.go index e6be17ad4..a96c0e2de 100644 --- a/pkg/commands/logging/syslog/describe.go +++ b/pkg/commands/logging/syslog/describe.go @@ -3,12 +3,12 @@ package syslog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a Syslog logging endpoint. @@ -16,19 +16,17 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetSyslogInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Syslog logging endpoint on a Fastly service version").Alias("get") @@ -46,7 +44,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/syslog/list.go b/pkg/commands/logging/syslog/list.go index 8df31e5e0..72e140896 100644 --- a/pkg/commands/logging/syslog/list.go +++ b/pkg/commands/logging/syslog/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list Syslog logging endpoints. @@ -17,19 +17,17 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListSyslogsInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Syslog endpoints on a Fastly service version") @@ -46,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/logging/syslog/syslog_integration_test.go b/pkg/commands/logging/syslog/syslog_integration_test.go index 9527851fc..311a807e3 100644 --- a/pkg/commands/logging/syslog/syslog_integration_test.go +++ b/pkg/commands/logging/syslog/syslog_integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestSyslogCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -118,8 +119,8 @@ func TestSyslogList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -163,8 +164,8 @@ func TestSyslogDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -210,8 +211,8 @@ func TestSyslogUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -257,8 +258,8 @@ func TestSyslogDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -290,7 +291,7 @@ func listSyslogsOK(i *fastly.ListSyslogsInput) ([]*fastly.Syslog, error) { ServiceVersion: i.ServiceVersion, Name: "logs", Address: "127.0.0.1", - Hostname: "", + Hostname: "127.0.0.1", Port: 514, UseTLS: false, IPV4: "127.0.0.1", @@ -313,7 +314,7 @@ func listSyslogsOK(i *fastly.ListSyslogsInput) ([]*fastly.Syslog, error) { Hostname: "example.com", Port: 789, UseTLS: true, - IPV4: "", + IPV4: "127.0.0.1", TLSCACert: "-----BEGIN CERTIFICATE-----baz", TLSHostname: "example.com", TLSClientCert: "-----BEGIN CERTIFICATE-----qux", @@ -350,7 +351,7 @@ Version: 1 Version: 1 Name: logs Address: 127.0.0.1 - Hostname: + Hostname: 127.0.0.1 Port: 514 Use TLS: false IPV4: 127.0.0.1 @@ -372,7 +373,7 @@ Version: 1 Hostname: example.com Port: 789 Use TLS: true - IPV4: + IPV4: 127.0.0.1 TLS CA certificate: -----BEGIN CERTIFICATE-----baz TLS hostname: example.com TLS client certificate: -----BEGIN CERTIFICATE-----qux diff --git a/pkg/commands/logging/syslog/update.go b/pkg/commands/logging/syslog/update.go index 5c406fa02..155a7a91d 100644 --- a/pkg/commands/logging/syslog/update.go +++ b/pkg/commands/logging/syslog/update.go @@ -3,13 +3,14 @@ package syslog import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/commands/logging/common" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a Syslog logging endpoint. @@ -41,12 +42,11 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - Manifest: m, } c.CmdClause = parent.Command("update", "Update a Syslog logging endpoint on a Fastly service version") @@ -75,7 +75,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.Manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -166,7 +166,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.AutoClone, APIClient: c.Globals.APIClient, - Manifest: c.Manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.ServiceName, ServiceVersionFlag: c.ServiceVersion, diff --git a/pkg/commands/logtail/root.go b/pkg/commands/logtail/root.go index 261300273..98228ea71 100644 --- a/pkg/commands/logtail/root.go +++ b/pkg/commands/logtail/root.go @@ -22,7 +22,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -37,21 +36,19 @@ type RootCommand struct { dieCh chan struct{} // channel to end output/printing doneCh chan struct{} // channel to signal we've reached the end of the run hClient *http.Client // TODO: this will go away when GET is in go-fastly - manifest manifest.Data serviceName cmd.OptionalServiceNameID token string // TODO: this will go away when GET is in go-fastly } // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *RootCommand { +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { var c RootCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("log-tail", "Tail Compute logs") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -70,7 +67,7 @@ func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Roo // Exec implements the command interface. func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/pop/pop_test.go b/pkg/commands/pop/pop_test.go index 416837b08..faaa3751f 100644 --- a/pkg/commands/pop/pop_test.go +++ b/pkg/commands/pop/pop_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -33,8 +34,8 @@ func TestAllDatacenters(t *testing.T) { }, nil }, } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(args, &stdout) opts.APIClientFactory = mock.APIClient(api) return opts, nil } diff --git a/pkg/commands/products/products_test.go b/pkg/commands/products/products_test.go index 472b5ceef..cb7689806 100644 --- a/pkg/commands/products/products_test.go +++ b/pkg/commands/products/products_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -134,8 +135,8 @@ Web Sockets true testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/products/root.go b/pkg/commands/products/root.go index ec2b13390..052a832e5 100644 --- a/pkg/commands/products/root.go +++ b/pkg/commands/products/root.go @@ -10,7 +10,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -22,7 +21,6 @@ type RootCommand struct { disableProduct string enableProduct string - manifest manifest.Data serviceName cmd.OptionalServiceNameID } @@ -37,10 +35,9 @@ var ProductEnablementOptions = []string{ } // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *RootCommand { +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { var c RootCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("products", "Enable, disable, and check the enablement status of products") // Optional. @@ -50,7 +47,7 @@ func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Roo c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -74,7 +71,7 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, _, _, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, _, _, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return fmt.Errorf("failed to identify Service ID: %w", err) } diff --git a/pkg/commands/profile/create.go b/pkg/commands/profile/create.go index eea8b8110..a177b8c83 100644 --- a/pkg/commands/profile/create.go +++ b/pkg/commands/profile/create.go @@ -27,13 +27,12 @@ type CreateCommand struct { authCmd *sso.RootCommand automationToken bool - clientFactory APIClientFactory profile string sso bool } // NewCreateCommand returns a new command registered in the parent. -func NewCreateCommand(parent cmd.Registerer, cf APIClientFactory, g *global.Data, authCmd *sso.RootCommand) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data, authCmd *sso.RootCommand) *CreateCommand { var c CreateCommand c.Globals = g c.authCmd = authCmd @@ -41,7 +40,6 @@ func NewCreateCommand(parent cmd.Registerer, cf APIClientFactory, g *global.Data c.CmdClause.Arg("profile", "Profile to create (default 'user')").Default(profile.DefaultName).Short('p').StringVar(&c.profile) c.CmdClause.Flag("automation-token", "Expected input will be an 'automation token' instead of a 'user token'").BoolVar(&c.automationToken) c.CmdClause.Flag("sso", "Create an SSO-based token").Hidden().BoolVar(&c.sso) - c.clientFactory = cf return &c } @@ -164,7 +162,7 @@ func (c *CreateCommand) validateToken(token, endpoint string, spinner text.Spinn t *fastly.Token ) err = spinner.Process("Validating token", func(_ *text.SpinnerWrapper) error { - client, err = c.clientFactory(token, endpoint, c.Globals.Flags.Debug) + client, err = c.Globals.APIClientFactory(token, endpoint, c.Globals.Flags.Debug) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ "Endpoint": endpoint, diff --git a/pkg/commands/profile/profile_test.go b/pkg/commands/profile/profile_test.go index 596a36bcd..3f5a6f7f1 100644 --- a/pkg/commands/profile/profile_test.go +++ b/pkg/commands/profile/profile_test.go @@ -14,6 +14,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/config" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -113,7 +114,7 @@ func TestCreate(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -123,7 +124,7 @@ func TestCreate(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile // TODO: abstract the logic for handling interactive stdin prompts. // This same if/else block is fundamentally duplicated across test files. @@ -131,7 +132,7 @@ func TestCreate(t *testing.T) { // To handle multiple prompt input from the user we need to do some // coordination around io pipes to mimic the required user behaviour. stdin, prompt := io.Pipe() - opts.Stdin = stdin + opts.Input = stdin // Wait for user input and write it to the prompt inputc := make(chan string) @@ -146,7 +147,7 @@ func TestCreate(t *testing.T) { // Call `app.Run()` and wait for response go func() { - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -173,8 +174,8 @@ func TestCreate(t *testing.T) { if len(testcase.Stdin) > 0 { stdin = testcase.Stdin[0] } - opts.Stdin = strings.NewReader(stdin) - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + opts.Input = strings.NewReader(stdin) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -264,7 +265,7 @@ func TestDelete(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -274,9 +275,9 @@ func TestDelete(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -481,7 +482,7 @@ func TestList(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -491,9 +492,9 @@ func TestList(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -587,7 +588,7 @@ func TestSwitch(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -597,9 +598,9 @@ func TestSwitch(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -735,7 +736,7 @@ func TestToken(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -745,9 +746,9 @@ func TestToken(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -850,7 +851,7 @@ func TestUpdate(t *testing.T) { stdout bytes.Buffer ) - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) // We override the config path so that we don't accidentally write over @@ -860,13 +861,13 @@ func TestUpdate(t *testing.T) { // The read of the config file only really happens in the main() // function, so for the sake of the test environment we need to construct // an in-memory representation of the config file we want to be using. - opts.ConfigFile = testcase.ConfigFile + opts.Config = testcase.ConfigFile if len(testcase.Stdin) > 1 { // To handle multiple prompt input from the user we need to do some // coordination around io pipes to mimic the required user behaviour. stdin, prompt := io.Pipe() - opts.Stdin = stdin + opts.Input = stdin // Wait for user input and write it to the prompt inputc := make(chan string) @@ -881,7 +882,7 @@ func TestUpdate(t *testing.T) { // Call `app.Run()` and wait for response go func() { - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -908,8 +909,8 @@ func TestUpdate(t *testing.T) { if len(testcase.Stdin) > 0 { stdin = testcase.Stdin[0] } - opts.Stdin = strings.NewReader(stdin) - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + opts.Input = strings.NewReader(stdin) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) diff --git a/pkg/commands/profile/update.go b/pkg/commands/profile/update.go index b5d17e472..81ffe6802 100644 --- a/pkg/commands/profile/update.go +++ b/pkg/commands/profile/update.go @@ -28,13 +28,12 @@ type UpdateCommand struct { authCmd *sso.RootCommand automationToken bool - clientFactory APIClientFactory profile string sso bool } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, cf APIClientFactory, g *global.Data, authCmd *sso.RootCommand) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data, authCmd *sso.RootCommand) *UpdateCommand { var c UpdateCommand c.Globals = g c.authCmd = authCmd @@ -42,7 +41,6 @@ func NewUpdateCommand(parent cmd.Registerer, cf APIClientFactory, g *global.Data c.CmdClause.Arg("profile", "Profile to update (defaults to the currently active profile)").Short('p').StringVar(&c.profile) c.CmdClause.Flag("automation-token", "Expected input will be an 'automation token' instead of a 'user token'").BoolVar(&c.automationToken) c.CmdClause.Flag("sso", "Update profile to use an SSO-based token").Hidden().BoolVar(&c.sso) - c.clientFactory = cf return &c } @@ -176,7 +174,7 @@ func (c *UpdateCommand) validateToken(token, endpoint string, spinner text.Spinn t *fastly.Token ) err = spinner.Process("Validating token", func(_ *text.SpinnerWrapper) error { - client, err = c.clientFactory(token, endpoint, c.Globals.Flags.Debug) + client, err = c.Globals.APIClientFactory(token, endpoint, c.Globals.Flags.Debug) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ "Endpoint": endpoint, diff --git a/pkg/commands/purge/purge_test.go b/pkg/commands/purge/purge_test.go index a0f92969e..c758765e5 100644 --- a/pkg/commands/purge/purge_test.go +++ b/pkg/commands/purge/purge_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -54,8 +55,8 @@ func TestPurgeAll(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -108,8 +109,8 @@ func TestPurgeKeys(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -188,8 +189,8 @@ func TestPurgeKey(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -246,8 +247,8 @@ func TestPurgeURL(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/purge/root.go b/pkg/commands/purge/root.go index 5addaaae9..c0ca73fd7 100644 --- a/pkg/commands/purge/root.go +++ b/pkg/commands/purge/root.go @@ -18,11 +18,10 @@ import ( ) // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *RootCommand { +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { var c RootCommand c.CmdClause = parent.Command("purge", "Invalidate objects in the Fastly cache") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("all", "Purge everything from a service").BoolVar(&c.all) @@ -31,7 +30,7 @@ func NewRootCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Roo c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -54,7 +53,6 @@ type RootCommand struct { all bool file string key string - manifest manifest.Data serviceName cmd.OptionalServiceNameID soft bool url string @@ -62,7 +60,7 @@ type RootCommand struct { // Exec implements the command interface. func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/ratelimit/create.go b/pkg/commands/ratelimit/create.go index 229748385..b6cc6e672 100644 --- a/pkg/commands/ratelimit/create.go +++ b/pkg/commands/ratelimit/create.go @@ -11,7 +11,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -43,12 +42,11 @@ var rateLimitWindowSizeFlagOpts = func() (windowSizes []string) { }() // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a rate limiter for a particular service and version").Alias("add") @@ -82,7 +80,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -108,7 +106,6 @@ type CreateCommand struct { featRevision int httpMethods string loggerType string - manifest manifest.Data name string penaltyDuration int responseContent string @@ -138,7 +135,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/ratelimit/delete.go b/pkg/commands/ratelimit/delete.go index 118e5a714..68ed9f054 100644 --- a/pkg/commands/ratelimit/delete.go +++ b/pkg/commands/ratelimit/delete.go @@ -7,16 +7,14 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, globals *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, globals *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Delete a rate limiter by its ID").Alias("remove") c.Globals = globals - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying the rate limiter").Required().StringVar(&c.id) @@ -28,8 +26,7 @@ func NewDeleteCommand(parent cmd.Registerer, globals *global.Data, m manifest.Da type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/ratelimit/describe.go b/pkg/commands/ratelimit/describe.go index 608d5a3a8..cc648f94e 100644 --- a/pkg/commands/ratelimit/describe.go +++ b/pkg/commands/ratelimit/describe.go @@ -9,15 +9,13 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Get a rate limiter by its ID").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying the rate limiter").Required().StringVar(&c.id) @@ -33,8 +31,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/ratelimit/list.go b/pkg/commands/ratelimit/list.go index dd31824b4..c3161b180 100644 --- a/pkg/commands/ratelimit/list.go +++ b/pkg/commands/ratelimit/list.go @@ -9,16 +9,14 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all rate limiters for a particular service and version") c.Globals = g - c.manifest = m // Required. c.RegisterFlag(cmd.StringFlagOpts{ @@ -33,7 +31,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -50,7 +48,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -64,7 +61,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/ratelimit/ratelimit_test.go b/pkg/commands/ratelimit/ratelimit_test.go index fc2553c3d..a14bbc64e 100644 --- a/pkg/commands/ratelimit/ratelimit_test.go +++ b/pkg/commands/ratelimit/ratelimit_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -46,8 +47,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -87,8 +88,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -135,8 +136,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -187,8 +188,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -231,8 +232,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/ratelimit/update.go b/pkg/commands/ratelimit/update.go index 74421ae4f..c4a9d3b2b 100644 --- a/pkg/commands/ratelimit/update.go +++ b/pkg/commands/ratelimit/update.go @@ -11,17 +11,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a rate limiter by its ID") @@ -60,7 +58,6 @@ type UpdateCommand struct { httpMethods string id string loggerType string - manifest manifest.Data name string penaltyDuration int responseContent string diff --git a/pkg/commands/resourcelink/create.go b/pkg/commands/resourcelink/create.go index e30876df1..11cb0b3d9 100644 --- a/pkg/commands/resourcelink/create.go +++ b/pkg/commands/resourcelink/create.go @@ -3,12 +3,12 @@ package resourcelink import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create a resource link. @@ -18,18 +18,16 @@ type CreateCommand struct { autoClone cmd.OptionalAutoClone input fastly.CreateResourceInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, input: fastly.CreateResourceInput{ // Kingpin requires the following to be initialized. ResourceID: new(string), @@ -58,7 +56,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C Name: cmd.FlagServiceIDName, Short: 's', Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, }) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceName, @@ -92,7 +90,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, @@ -100,7 +98,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { }) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ - "Service ID": c.manifest.Flag.ServiceID, + "Service ID": c.Globals.Manifest.Flag.ServiceID, "Service Version": fsterr.ServiceVersion(serviceVersion), }) return err diff --git a/pkg/commands/resourcelink/delete.go b/pkg/commands/resourcelink/delete.go index ec1c7a228..fee8b6c3b 100644 --- a/pkg/commands/resourcelink/delete.go +++ b/pkg/commands/resourcelink/delete.go @@ -3,12 +3,12 @@ package resourcelink import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete service resource links. @@ -18,18 +18,16 @@ type DeleteCommand struct { autoClone cmd.OptionalAutoClone input fastly.DeleteResourceInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a resource link for a Fastly service version").Alias("remove") @@ -52,7 +50,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D Name: cmd.FlagServiceIDName, Short: 's', Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, }) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceName, @@ -80,7 +78,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, @@ -88,7 +86,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { }) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ - "Service ID": c.manifest.Flag.ServiceID, + "Service ID": c.Globals.Manifest.Flag.ServiceID, "Service Version": fsterr.ServiceVersion(serviceVersion), }) return err diff --git a/pkg/commands/resourcelink/describe.go b/pkg/commands/resourcelink/describe.go index 9c460f8c9..04871dd52 100644 --- a/pkg/commands/resourcelink/describe.go +++ b/pkg/commands/resourcelink/describe.go @@ -3,12 +3,12 @@ package resourcelink import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a service resource link. @@ -17,18 +17,16 @@ type DescribeCommand struct { cmd.JSONOutput input fastly.GetResourceInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Fastly service resource link").Alias("get") @@ -51,7 +49,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) Name: cmd.FlagServiceIDName, Short: 's', Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, }) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceName, @@ -72,7 +70,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/resourcelink/list.go b/pkg/commands/resourcelink/list.go index c5f64ec08..46f91183d 100644 --- a/pkg/commands/resourcelink/list.go +++ b/pkg/commands/resourcelink/list.go @@ -9,7 +9,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -19,18 +18,16 @@ type ListCommand struct { cmd.JSONOutput input fastly.ListResourcesInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List all resource links for a Fastly service version") @@ -47,7 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis Name: cmd.FlagServiceIDName, Short: 's', Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, }) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceName, @@ -68,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/resourcelink/resourcelink_test.go b/pkg/commands/resourcelink/resourcelink_test.go index 9cf23064c..6a046f579 100644 --- a/pkg/commands/resourcelink/resourcelink_test.go +++ b/pkg/commands/resourcelink/resourcelink_test.go @@ -12,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/resourcelink" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -147,7 +148,7 @@ func TestCreateServiceResourceCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(resourcelink.RootName + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.CreateResourceFn var apiInvoked bool @@ -156,7 +157,7 @@ func TestCreateServiceResourceCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -252,7 +253,7 @@ func TestDeleteServiceResourceCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(resourcelink.RootName + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.DeleteResourceFn var apiInvoked bool @@ -261,7 +262,7 @@ func TestDeleteServiceResourceCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -349,7 +350,7 @@ Last edited (UTC): 2023-10-15 12:18`, t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(resourcelink.RootName + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.GetResourceFn var apiInvoked bool @@ -358,7 +359,7 @@ Last edited (UTC): 2023-10-15 12:18`, return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -464,7 +465,7 @@ Resource Link 3/3 t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(resourcelink.RootName + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.ListResourcesFn var apiInvoked bool @@ -473,7 +474,7 @@ Resource Link 3/3 return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -602,7 +603,7 @@ func TestUpdateServiceResourceCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(resourcelink.RootName + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.UpdateResourceFn var apiInvoked bool @@ -611,7 +612,7 @@ func TestUpdateServiceResourceCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/resourcelink/update.go b/pkg/commands/resourcelink/update.go index 5c8d1fca5..c83673452 100644 --- a/pkg/commands/resourcelink/update.go +++ b/pkg/commands/resourcelink/update.go @@ -3,12 +3,12 @@ package resourcelink import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update a dictionary. @@ -18,18 +18,16 @@ type UpdateCommand struct { autoClone cmd.OptionalAutoClone input fastly.UpdateResourceInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, input: fastly.UpdateResourceInput{ // Kingpin requires the following to be initialized. Name: new(string), @@ -63,7 +61,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U Name: cmd.FlagServiceIDName, Short: 's', Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, }) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceName, @@ -91,7 +89,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, @@ -99,7 +97,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { }) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ - "Service ID": c.manifest.Flag.ServiceID, + "Service ID": c.Globals.Manifest.Flag.ServiceID, "Service Version": fsterr.ServiceVersion(serviceVersion), }) return err diff --git a/pkg/commands/secretstore/create.go b/pkg/commands/secretstore/create.go index 05f3ac448..26b14129e 100644 --- a/pkg/commands/secretstore/create.go +++ b/pkg/commands/secretstore/create.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new secret store") @@ -37,8 +35,7 @@ type CreateCommand struct { cmd.Base cmd.JSONOutput - Input fastly.CreateSecretStoreInput - manifest manifest.Data + Input fastly.CreateSecretStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstore/delete.go b/pkg/commands/secretstore/delete.go index 2982a0722..2cbe18c6d 100644 --- a/pkg/commands/secretstore/delete.go +++ b/pkg/commands/secretstore/delete.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a secret store") @@ -37,8 +35,7 @@ type DeleteCommand struct { cmd.Base cmd.JSONOutput - Input fastly.DeleteSecretStoreInput - manifest manifest.Data + Input fastly.DeleteSecretStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstore/describe.go b/pkg/commands/secretstore/describe.go index fab9086c9..be8cb1b5c 100644 --- a/pkg/commands/secretstore/describe.go +++ b/pkg/commands/secretstore/describe.go @@ -3,21 +3,20 @@ package secretstore import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single secret store").Alias("get") @@ -36,8 +35,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - Input fastly.GetSecretStoreInput - manifest manifest.Data + Input fastly.GetSecretStoreInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstore/list.go b/pkg/commands/secretstore/list.go index 7411c3cb8..a89309fa4 100644 --- a/pkg/commands/secretstore/list.go +++ b/pkg/commands/secretstore/list.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List secret stores") @@ -37,8 +35,7 @@ type ListCommand struct { cmd.JSONOutput // NOTE: API returns 10 items even when --limit is set to smaller. - Input fastly.ListSecretStoresInput - manifest manifest.Data + Input fastly.ListSecretStoresInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstore/secretstore_test.go b/pkg/commands/secretstore/secretstore_test.go index 96be7878f..0308d2c56 100644 --- a/pkg/commands/secretstore/secretstore_test.go +++ b/pkg/commands/secretstore/secretstore_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/secretstore" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -79,7 +80,7 @@ func TestCreateStoreCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstore.RootNameStore + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.CreateSecretStoreFn var apiInvoked bool @@ -88,7 +89,7 @@ func TestCreateStoreCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -164,7 +165,7 @@ func TestDeleteStoreCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstore.RootNameStore + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.DeleteSecretStoreFn var apiInvoked bool @@ -173,7 +174,7 @@ func TestDeleteStoreCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -254,7 +255,7 @@ func TestDescribeStoreCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstore.RootNameStore + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.GetSecretStoreFn var apiInvoked bool @@ -263,7 +264,7 @@ func TestDescribeStoreCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -346,7 +347,7 @@ func TestListStoresCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstore.RootNameStore + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.ListSecretStoresFn var apiInvoked bool @@ -355,7 +356,7 @@ func TestListStoresCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/secretstoreentry/create.go b/pkg/commands/secretstoreentry/create.go index ce7bd7bf6..0d6a9559d 100644 --- a/pkg/commands/secretstoreentry/create.go +++ b/pkg/commands/secretstoreentry/create.go @@ -14,7 +14,6 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -43,12 +42,11 @@ func mustDecode(s string) []byte { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a new secret within specified store") @@ -83,7 +81,6 @@ type CreateCommand struct { cmd.JSONOutput Input fastly.CreateSecretInput - manifest manifest.Data recreate bool recreateAllow bool secretFile string diff --git a/pkg/commands/secretstoreentry/delete.go b/pkg/commands/secretstoreentry/delete.go index 05d8bcb8b..eda3b040d 100644 --- a/pkg/commands/secretstoreentry/delete.go +++ b/pkg/commands/secretstoreentry/delete.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a secret") @@ -38,8 +36,7 @@ type DeleteCommand struct { cmd.Base cmd.JSONOutput - Input fastly.DeleteSecretInput - manifest manifest.Data + Input fastly.DeleteSecretInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstoreentry/describe.go b/pkg/commands/secretstoreentry/describe.go index 654cf1fd3..45d7551ba 100644 --- a/pkg/commands/secretstoreentry/describe.go +++ b/pkg/commands/secretstoreentry/describe.go @@ -3,21 +3,20 @@ package secretstoreentry import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Retrieve a single secret").Alias("get") @@ -37,8 +36,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - Input fastly.GetSecretInput - manifest manifest.Data + Input fastly.GetSecretInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstoreentry/list.go b/pkg/commands/secretstoreentry/list.go index ad8fef6c5..2185d1f9a 100644 --- a/pkg/commands/secretstoreentry/list.go +++ b/pkg/commands/secretstoreentry/list.go @@ -8,17 +8,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List secrets within a specified store") @@ -39,8 +37,7 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - Input fastly.ListSecretsInput - manifest manifest.Data + Input fastly.ListSecretsInput } // Exec invokes the application logic for the command. diff --git a/pkg/commands/secretstoreentry/secretstoreentry_test.go b/pkg/commands/secretstoreentry/secretstoreentry_test.go index c97756bd6..2eea5bf9b 100644 --- a/pkg/commands/secretstoreentry/secretstoreentry_test.go +++ b/pkg/commands/secretstoreentry/secretstoreentry_test.go @@ -21,6 +21,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/commands/secretstoreentry" fstfmt "github.com/fastly/cli/pkg/fmt" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -229,11 +230,11 @@ func TestCreateSecretCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstoreentry.RootNameSecret + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) if testcase.stdin != "" { var stdin bytes.Buffer stdin.WriteString(testcase.stdin) - opts.Stdin = &stdin + opts.Input = &stdin } f := testcase.api.CreateSecretFn @@ -248,7 +249,7 @@ func TestCreateSecretCommand(t *testing.T) { // hardcoded value. t.Setenv("FASTLY_USE_API_SIGNING_KEY", "1") - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -330,7 +331,7 @@ func TestDeleteSecretCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstoreentry.RootNameSecret + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.DeleteSecretFn var apiInvoked bool @@ -339,7 +340,7 @@ func TestDeleteSecretCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -437,7 +438,7 @@ func TestDescribeSecretCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstoreentry.RootNameSecret + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.GetSecretFn var apiInvoked bool @@ -446,7 +447,7 @@ func TestDescribeSecretCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -525,7 +526,7 @@ func TestListSecretsCommand(t *testing.T) { t.Run(testcase.args, func(t *testing.T) { var stdout bytes.Buffer args := testutil.Args(secretstoreentry.RootNameSecret + " " + testcase.args) - opts := testutil.NewRunOpts(args, &stdout) + opts := testutil.MockGlobalData(args, &stdout) f := testcase.api.ListSecretsFn var apiInvoked bool @@ -534,7 +535,7 @@ func TestListSecretsCommand(t *testing.T) { return f(i) } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/service/create.go b/pkg/commands/service/create.go index a3f2915d1..f1cd726e0 100644 --- a/pkg/commands/service/create.go +++ b/pkg/commands/service/create.go @@ -3,10 +3,11 @@ package service import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CreateCommand calls the Fastly API to create services. diff --git a/pkg/commands/service/delete.go b/pkg/commands/service/delete.go index e79d36ab3..7edf72bdc 100644 --- a/pkg/commands/service/delete.go +++ b/pkg/commands/service/delete.go @@ -4,30 +4,29 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete services. type DeleteCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeleteServiceInput force bool serviceName cmd.OptionalServiceNameID } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a Fastly service").Alias("remove") @@ -36,7 +35,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -50,7 +49,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } @@ -99,12 +98,12 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { // Ensure that VCL service users are unaffected by checking if the Service ID // was acquired via the fastly.toml manifest. if source == manifest.SourceFile { - if err := c.manifest.File.Read(manifest.Filename); err != nil { + if err := c.Globals.Manifest.File.Read(manifest.Filename); err != nil { c.Globals.ErrLog.Add(err) return fmt.Errorf("error reading fastly.toml: %w", err) } - c.manifest.File.ServiceID = "" - if err := c.manifest.File.Write(manifest.Filename); err != nil { + c.Globals.Manifest.File.ServiceID = "" + if err := c.Globals.Manifest.File.Write(manifest.Filename); err != nil { c.Globals.ErrLog.Add(err) return fmt.Errorf("error updating fastly.toml: %w", err) } diff --git a/pkg/commands/service/describe.go b/pkg/commands/service/describe.go index 7a6836b25..d4598ac8c 100644 --- a/pkg/commands/service/describe.go +++ b/pkg/commands/service/describe.go @@ -5,13 +5,14 @@ import ( "io" "strconv" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" "github.com/fastly/cli/pkg/time" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a service. @@ -19,18 +20,16 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.GetServiceInput serviceName cmd.OptionalServiceNameID } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show detailed information about a Fastly service").Alias("get") @@ -39,7 +38,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -57,7 +56,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/service/search.go b/pkg/commands/service/search.go index c02e1ec1d..eaa0391b0 100644 --- a/pkg/commands/service/search.go +++ b/pkg/commands/service/search.go @@ -3,12 +3,12 @@ package service import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // SearchCommand calls the Fastly API to describe a service. @@ -16,17 +16,15 @@ type SearchCommand struct { cmd.Base cmd.JSONOutput - Input fastly.SearchServiceInput - manifest manifest.Data + Input fastly.SearchServiceInput } // NewSearchCommand returns a usable command registered under the parent. -func NewSearchCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *SearchCommand { +func NewSearchCommand(parent cmd.Registerer, g *global.Data) *SearchCommand { c := SearchCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("search", "Search for a Fastly service by name") diff --git a/pkg/commands/service/service_test.go b/pkg/commands/service/service_test.go index 585d8a8ee..5bf506b5f 100644 --- a/pkg/commands/service/service_test.go +++ b/pkg/commands/service/service_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" @@ -61,8 +62,8 @@ func TestServiceCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -137,8 +138,8 @@ func TestServiceList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -197,8 +198,8 @@ func TestServiceDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -241,8 +242,8 @@ func TestServiceSearch(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -309,8 +310,8 @@ func TestServiceUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -400,8 +401,8 @@ func TestServiceDelete(t *testing.T) { }() var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - runOpts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + runOpts := testutil.MockGlobalData(testcase.args, &stdout) runOpts.APIClientFactory = mock.APIClient(testcase.api) return runOpts, nil } diff --git a/pkg/commands/service/update.go b/pkg/commands/service/update.go index e5721457b..26da2248b 100644 --- a/pkg/commands/service/update.go +++ b/pkg/commands/service/update.go @@ -4,11 +4,11 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to create services. @@ -17,18 +17,16 @@ type UpdateCommand struct { comment cmd.OptionalString input fastly.UpdateServiceInput - manifest manifest.Data name cmd.OptionalString serviceName cmd.OptionalServiceNameID } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a Fastly service") @@ -38,7 +36,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -52,7 +50,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/serviceauth/create.go b/pkg/commands/serviceauth/create.go index 94461b3c1..da62f1ae1 100644 --- a/pkg/commands/serviceauth/create.go +++ b/pkg/commands/serviceauth/create.go @@ -7,7 +7,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -19,18 +18,16 @@ var Permissions = []string{"full", "read_only", "purge_select", "purge_all"} type CreateCommand struct { cmd.Base input fastly.CreateServiceAuthorizationInput - manifest manifest.Data serviceName cmd.OptionalServiceNameID userID string } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create service authorization").Alias("add") @@ -44,7 +41,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -58,10 +55,10 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ - "Service ID": c.manifest.Flag.ServiceID, + "Service ID": c.Globals.Manifest.Flag.ServiceID, "Service Name": c.serviceName.Value, }) return err diff --git a/pkg/commands/serviceauth/delete.go b/pkg/commands/serviceauth/delete.go index 7526127c3..aa6d34224 100644 --- a/pkg/commands/serviceauth/delete.go +++ b/pkg/commands/serviceauth/delete.go @@ -3,27 +3,25 @@ package serviceauth import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete service authorizations. type DeleteCommand struct { cmd.Base - manifest manifest.Data - Input fastly.DeleteServiceAuthorizationInput + Input fastly.DeleteServiceAuthorizationInput } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete service authorization").Alias("remove") diff --git a/pkg/commands/serviceauth/describe.go b/pkg/commands/serviceauth/describe.go index dc141ca14..6d127c004 100644 --- a/pkg/commands/serviceauth/describe.go +++ b/pkg/commands/serviceauth/describe.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/time" - "github.com/fastly/go-fastly/v8/fastly" ) // DescribeCommand calls the Fastly API to describe a service authorization. @@ -17,17 +17,15 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.GetServiceAuthorizationInput + Input fastly.GetServiceAuthorizationInput } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Show service authorization").Alias("get") diff --git a/pkg/commands/serviceauth/service_test.go b/pkg/commands/serviceauth/service_test.go index eb5cbcd94..88941b1e1 100644 --- a/pkg/commands/serviceauth/service_test.go +++ b/pkg/commands/serviceauth/service_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -41,8 +42,8 @@ func TestServiceAuthCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -110,8 +111,8 @@ func TestServiceAuthList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -171,8 +172,8 @@ func TestServiceAuthDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -215,8 +216,8 @@ func TestServiceAuthUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -254,8 +255,8 @@ func TestServiceAuthDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/serviceauth/update.go b/pkg/commands/serviceauth/update.go index 38b215072..c0b4079a5 100644 --- a/pkg/commands/serviceauth/update.go +++ b/pkg/commands/serviceauth/update.go @@ -3,28 +3,26 @@ package serviceauth import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // UpdateCommand calls the Fastly API to update service authorizations. type UpdateCommand struct { cmd.Base - input fastly.UpdateServiceAuthorizationInput - manifest manifest.Data + input fastly.UpdateServiceAuthorizationInput } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update service authorization") diff --git a/pkg/commands/serviceversion/activate.go b/pkg/commands/serviceversion/activate.go index ee2c69233..fd85144ae 100644 --- a/pkg/commands/serviceversion/activate.go +++ b/pkg/commands/serviceversion/activate.go @@ -3,18 +3,17 @@ package serviceversion import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ActivateCommand calls the Fastly API to activate a service version. type ActivateCommand struct { cmd.Base - manifest manifest.Data Input fastly.ActivateVersionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,15 +21,14 @@ type ActivateCommand struct { } // NewActivateCommand returns a usable command registered under the parent. -func NewActivateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ActivateCommand { +func NewActivateCommand(parent cmd.Registerer, g *global.Data) *ActivateCommand { var c ActivateCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("activate", "Activate a Fastly service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -57,7 +55,7 @@ func (c *ActivateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/serviceversion/clone.go b/pkg/commands/serviceversion/clone.go index 10c1c5b1d..69f66e507 100644 --- a/pkg/commands/serviceversion/clone.go +++ b/pkg/commands/serviceversion/clone.go @@ -3,33 +3,31 @@ package serviceversion import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // CloneCommand calls the Fastly API to clone a service version. type CloneCommand struct { cmd.Base - manifest manifest.Data Input fastly.CloneVersionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewCloneCommand returns a usable command registered under the parent. -func NewCloneCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CloneCommand { +func NewCloneCommand(parent cmd.Registerer, g *global.Data) *CloneCommand { var c CloneCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("clone", "Clone a Fastly service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -52,7 +50,7 @@ func (c *CloneCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/serviceversion/deactivate.go b/pkg/commands/serviceversion/deactivate.go index d569e5a9e..64056afc0 100644 --- a/pkg/commands/serviceversion/deactivate.go +++ b/pkg/commands/serviceversion/deactivate.go @@ -3,33 +3,31 @@ package serviceversion import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeactivateCommand calls the Fastly API to deactivate a service version. type DeactivateCommand struct { cmd.Base - manifest manifest.Data Input fastly.DeactivateVersionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDeactivateCommand returns a usable command registered under the parent. -func NewDeactivateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeactivateCommand { +func NewDeactivateCommand(parent cmd.Registerer, g *global.Data) *DeactivateCommand { var c DeactivateCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("deactivate", "Deactivate a Fastly service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -52,7 +50,7 @@ func (c *DeactivateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/serviceversion/list.go b/pkg/commands/serviceversion/list.go index 17d6c775c..20aca08eb 100644 --- a/pkg/commands/serviceversion/list.go +++ b/pkg/commands/serviceversion/list.go @@ -4,13 +4,13 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" "github.com/fastly/cli/pkg/time" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list services. @@ -18,25 +18,23 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data Input fastly.ListVersionsInput serviceName cmd.OptionalServiceNameID } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List Fastly service versions") c.RegisterFlagBool(c.JSONFlag()) // --json c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -54,7 +52,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/serviceversion/lock.go b/pkg/commands/serviceversion/lock.go index 64e6133a1..3aaf91db7 100644 --- a/pkg/commands/serviceversion/lock.go +++ b/pkg/commands/serviceversion/lock.go @@ -3,33 +3,31 @@ package serviceversion import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // LockCommand calls the Fastly API to lock a service version. type LockCommand struct { cmd.Base - manifest manifest.Data Input fastly.LockVersionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewLockCommand returns a usable command registered under the parent. -func NewLockCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *LockCommand { +func NewLockCommand(parent cmd.Registerer, g *global.Data) *LockCommand { var c LockCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("lock", "Lock a Fastly service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -52,7 +50,7 @@ func (c *LockCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/serviceversion/serviceversion_test.go b/pkg/commands/serviceversion/serviceversion_test.go index 2d5976dcd..401a3970d 100644 --- a/pkg/commands/serviceversion/serviceversion_test.go +++ b/pkg/commands/serviceversion/serviceversion_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -50,8 +51,8 @@ func TestVersionClone(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -105,8 +106,8 @@ func TestVersionList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -156,8 +157,8 @@ func TestVersionUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -211,8 +212,8 @@ func TestVersionActivate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -264,8 +265,8 @@ func TestVersionDeactivate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } @@ -309,8 +310,8 @@ func TestVersionLock(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/serviceversion/update.go b/pkg/commands/serviceversion/update.go index b747f0c47..c1176f775 100644 --- a/pkg/commands/serviceversion/update.go +++ b/pkg/commands/serviceversion/update.go @@ -9,14 +9,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // UpdateCommand calls the Fastly API to update a service version. type UpdateCommand struct { cmd.Base - manifest manifest.Data input fastly.UpdateVersionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -26,18 +24,17 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a Fastly service version") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -71,7 +68,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/sso/root.go b/pkg/commands/sso/root.go index ba133b762..b9451004d 100644 --- a/pkg/commands/sso/root.go +++ b/pkg/commands/sso/root.go @@ -19,9 +19,7 @@ import ( // It should be installed under the primary root command. type RootCommand struct { cmd.Base - authServer auth.Starter - openBrowser func(string) error - profile string + profile string // IMPORTANT: The following fields are public to the `profile` subcommands. @@ -38,10 +36,8 @@ type RootCommand struct { } // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, g *global.Data, opener func(string) error, authServer auth.Starter) *RootCommand { +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { var c RootCommand - c.authServer = authServer - c.openBrowser = opener c.Globals = g // FIXME: Unhide this command once SSO authentication goes GA. c.CmdClause = parent.Command("sso", "Single Sign-On authentication").Hidden() @@ -73,20 +69,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { accountEndpoint, _ := c.Globals.AccountEndpoint() apiEndpoint, _ := c.Globals.APIEndpoint() - verifier, err := auth.GenVerifier() - if err != nil { - return fsterr.RemediationError{ - Inner: fmt.Errorf("failed to generate a code verifier: %w", err), - Remediation: auth.Remediation, - } - } - c.authServer.SetAccountEndpoint(accountEndpoint) - c.authServer.SetAPIEndpoint(apiEndpoint) - c.authServer.SetVerifier(verifier) + c.Globals.AuthServer.SetAccountEndpoint(accountEndpoint) + c.Globals.AuthServer.SetAPIEndpoint(apiEndpoint) var serverErr error go func() { - err := c.authServer.Start() + err := c.Globals.AuthServer.Start() if err != nil { serverErr = err } @@ -97,7 +85,7 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { text.Info(out, "Starting a local server to handle the authentication flow.") - authorizationURL, err := auth.GenURL(accountEndpoint, apiEndpoint, verifier) + authorizationURL, err := c.Globals.AuthServer.AuthURL() if err != nil { return fsterr.RemediationError{ Inner: fmt.Errorf("failed to generate an authorization URL: %w", err), @@ -108,12 +96,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { text.Break(out) text.Description(out, "We're opening the following URL in your default web browser so you may authenticate with Fastly", authorizationURL) - err = c.openBrowser(authorizationURL) + err = c.Globals.Opener(authorizationURL) if err != nil { return fmt.Errorf("failed to open your default browser: %w", err) } - ar := <-c.authServer.GetResult() + ar := <-c.Globals.AuthServer.GetResult() if ar.Err != nil || ar.SessionToken == "" { err := ar.Err if ar.Err == nil { diff --git a/pkg/commands/sso/sso_test.go b/pkg/commands/sso/sso_test.go index 57f6049ef..03d106859 100644 --- a/pkg/commands/sso/sso_test.go +++ b/pkg/commands/sso/sso_test.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/auth" "github.com/fastly/cli/pkg/config" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -226,14 +227,14 @@ func TestSSO(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - opts := testutil.NewRunOpts(testcase.Args, &stdout) + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) if testcase.HTTPClient != nil { opts.HTTPClient = testcase.HTTPClient } if testcase.ConfigFile != nil { - opts.ConfigFile = *testcase.ConfigFile + opts.Config = *testcase.ConfigFile } if testcase.Opener != nil { opts.Opener = testcase.Opener @@ -254,7 +255,7 @@ func TestSSO(t *testing.T) { // To handle multiple prompt input from the user we need to do some // coordination around io pipes to mimic the required user behaviour. stdin, prompt := io.Pipe() - opts.Stdin = stdin + opts.Input = stdin // Wait for user input and write it to the prompt inputc := make(chan string) @@ -269,7 +270,7 @@ func TestSSO(t *testing.T) { // Call `app.Run()` and wait for response go func() { - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -296,8 +297,8 @@ func TestSSO(t *testing.T) { if len(testcase.Stdin) > 0 { stdin = testcase.Stdin[0] } - opts.Stdin = strings.NewReader(stdin) - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + opts.Input = strings.NewReader(stdin) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(testcase.Args, nil) @@ -308,7 +309,7 @@ func TestSSO(t *testing.T) { if len(testcase.Args) > 1 { profileName = testcase.Args[1] // use the `profile` command argument } - userProfile := opts.ConfigFile.Profiles[profileName] + userProfile := opts.Config.Profiles[profileName] if userProfile.Token != testcase.ExpectedConfigProfile.Token { t.Errorf("want token: %s, got token: %s", testcase.ExpectedConfigProfile.Token, userProfile.Token) } diff --git a/pkg/commands/stats/historical.go b/pkg/commands/stats/historical.go index a05e46b37..4a2a3cb99 100644 --- a/pkg/commands/stats/historical.go +++ b/pkg/commands/stats/historical.go @@ -9,7 +9,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) const statusSuccess = "success" @@ -17,7 +16,6 @@ const statusSuccess = "success" // HistoricalCommand exposes the Historical Stats API. type HistoricalCommand struct { cmd.Base - manifest manifest.Data Input fastly.GetStatsInput formatFlag string @@ -25,16 +23,15 @@ type HistoricalCommand struct { } // NewHistoricalCommand is the "stats historical" subcommand. -func NewHistoricalCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *HistoricalCommand { +func NewHistoricalCommand(parent cmd.Registerer, g *global.Data) *HistoricalCommand { var c HistoricalCommand c.Globals = g - c.manifest = m c.CmdClause = parent.Command("historical", "View historical stats for a Fastly service") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -56,7 +53,7 @@ func NewHistoricalCommand(parent cmd.Registerer, g *global.Data, m manifest.Data // Exec implements the command interface. func (c *HistoricalCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/stats/historical_test.go b/pkg/commands/stats/historical_test.go index ba5d65480..3605c65bb 100644 --- a/pkg/commands/stats/historical_test.go +++ b/pkg/commands/stats/historical_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -42,8 +43,8 @@ func TestHistorical(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/stats/realtime.go b/pkg/commands/stats/realtime.go index d9c771b9b..d8df25c60 100644 --- a/pkg/commands/stats/realtime.go +++ b/pkg/commands/stats/realtime.go @@ -5,34 +5,32 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/api" "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // RealtimeCommand exposes the Realtime Metrics API. type RealtimeCommand struct { cmd.Base - manifest manifest.Data formatFlag string serviceName cmd.OptionalServiceNameID } // NewRealtimeCommand is the "stats realtime" subcommand. -func NewRealtimeCommand(parent cmd.Registerer, g *global.Data, data manifest.Data) *RealtimeCommand { +func NewRealtimeCommand(parent cmd.Registerer, g *global.Data) *RealtimeCommand { var c RealtimeCommand c.Globals = g - c.manifest = data c.CmdClause = parent.Command("realtime", "View realtime stats for a Fastly service") c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -49,7 +47,7 @@ func NewRealtimeCommand(parent cmd.Registerer, g *global.Data, data manifest.Dat // Exec implements the command interface. func (c *RealtimeCommand) Exec(_ io.Reader, out io.Writer) error { - serviceID, source, flag, err := cmd.ServiceID(c.serviceName, c.manifest, c.Globals.APIClient, c.Globals.ErrLog) + serviceID, source, flag, err := cmd.ServiceID(c.serviceName, *c.Globals.Manifest, c.Globals.APIClient, c.Globals.ErrLog) if err != nil { return err } diff --git a/pkg/commands/stats/regions_test.go b/pkg/commands/stats/regions_test.go index 66fadb5ff..d01b09134 100644 --- a/pkg/commands/stats/regions_test.go +++ b/pkg/commands/stats/regions_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -37,8 +38,8 @@ func TestRegions(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.api) return opts, nil } diff --git a/pkg/commands/tls/config/config_test.go b/pkg/commands/tls/config/config_test.go index f522a8ee5..e455ad9ae 100644 --- a/pkg/commands/tls/config/config_test.go +++ b/pkg/commands/tls/config/config_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -70,8 +71,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -130,8 +131,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -183,8 +184,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/config/describe.go b/pkg/commands/tls/config/describe.go index 55c74fbbb..e4bae4ece 100644 --- a/pkg/commands/tls/config/describe.go +++ b/pkg/commands/tls/config/describe.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) const include = "dns_records" // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show a TLS configuration").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS configuration").Required().StringVar(&c.id) @@ -35,9 +34,8 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - include string - manifest manifest.Data + id string + include string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/config/list.go b/pkg/commands/tls/config/list.go index 8bd2fde28..92e18b228 100644 --- a/pkg/commands/tls/config/list.go +++ b/pkg/commands/tls/config/list.go @@ -5,20 +5,19 @@ import ( "io" "strings" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS configurations") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-bulk", "Optionally filter by the bulk attribute").Action(c.filterBulk.Set).BoolVar(&c.filterBulk.Value) @@ -37,7 +36,6 @@ type ListCommand struct { filterBulk cmd.OptionalBool include string - manifest manifest.Data pageNumber int pageSize int } diff --git a/pkg/commands/tls/config/update.go b/pkg/commands/tls/config/update.go index a3e1683e3..e5c1c3b85 100644 --- a/pkg/commands/tls/config/update.go +++ b/pkg/commands/tls/config/update.go @@ -3,19 +3,18 @@ package config import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Update a TLS configuration") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS configuration").Required().StringVar(&c.id) @@ -27,9 +26,8 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U type UpdateCommand struct { cmd.Base - id string - manifest manifest.Data - name string + id string + name string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/activation/activation_test.go b/pkg/commands/tls/custom/activation/activation_test.go index c370e35d0..277dd6a1f 100644 --- a/pkg/commands/tls/custom/activation/activation_test.go +++ b/pkg/commands/tls/custom/activation/activation_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -65,8 +66,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -111,8 +112,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -161,8 +162,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -208,8 +209,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -264,8 +265,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/custom/activation/create.go b/pkg/commands/tls/custom/activation/create.go index 878bdb6f1..80145488d 100644 --- a/pkg/commands/tls/custom/activation/create.go +++ b/pkg/commands/tls/custom/activation/create.go @@ -3,19 +3,18 @@ package activation import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("enable", "Enable TLS for a particular TLS domain and certificate combination").Alias("add") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("cert-id", "Alphanumeric string identifying a TLS certificate").Required().StringVar(&c.certID) @@ -28,9 +27,8 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C type CreateCommand struct { cmd.Base - certID string - id string - manifest manifest.Data + certID string + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/activation/delete.go b/pkg/commands/tls/custom/activation/delete.go index 8fe8f2360..5deb1ee3f 100644 --- a/pkg/commands/tls/custom/activation/delete.go +++ b/pkg/commands/tls/custom/activation/delete.go @@ -3,19 +3,18 @@ package activation import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("disable", "Disable TLS on the domain associated with this TLS activation").Alias("remove") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS activation").Required().StringVar(&c.id) @@ -27,8 +26,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/activation/describe.go b/pkg/commands/tls/custom/activation/describe.go index 966bbd952..bfd82d7bb 100644 --- a/pkg/commands/tls/custom/activation/describe.go +++ b/pkg/commands/tls/custom/activation/describe.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) var include = []string{"tls_certificate", "tls_configuration", "tls_domain"} // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show a TLS configuration").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS activation").Required().StringVar(&c.id) @@ -35,9 +34,8 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - include string - manifest manifest.Data + id string + include string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/activation/list.go b/pkg/commands/tls/custom/activation/list.go index 831a6343b..9525e76fa 100644 --- a/pkg/commands/tls/custom/activation/list.go +++ b/pkg/commands/tls/custom/activation/list.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS activations") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-cert", "Limit the returned activations to a specific certificate").StringVar(&c.filterTLSCertID) @@ -40,7 +39,6 @@ type ListCommand struct { filterTLSConfigID string filterTLSDomainID string include string - manifest manifest.Data pageNumber int pageSize int } diff --git a/pkg/commands/tls/custom/activation/update.go b/pkg/commands/tls/custom/activation/update.go index 61ac31b4f..f8345ebf1 100644 --- a/pkg/commands/tls/custom/activation/update.go +++ b/pkg/commands/tls/custom/activation/update.go @@ -3,19 +3,18 @@ package activation import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Update the certificate used to terminate TLS traffic for the domain associated with this TLS activation") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("cert-id", "Alphanumeric string identifying a TLS certificate").Required().StringVar(&c.certID) @@ -27,9 +26,8 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U type UpdateCommand struct { cmd.Base - certID string - id string - manifest manifest.Data + certID string + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/certificate/certificate_test.go b/pkg/commands/tls/custom/certificate/certificate_test.go index 88578036d..1b62f25e0 100644 --- a/pkg/commands/tls/custom/certificate/certificate_test.go +++ b/pkg/commands/tls/custom/certificate/certificate_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -57,8 +58,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -103,8 +104,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -160,8 +161,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -214,8 +215,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -280,8 +281,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/custom/certificate/create.go b/pkg/commands/tls/custom/certificate/create.go index e240fdaaa..04aab4ff3 100644 --- a/pkg/commands/tls/custom/certificate/create.go +++ b/pkg/commands/tls/custom/certificate/create.go @@ -3,19 +3,18 @@ package certificate import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("create", "Create a TLS certificate").Alias("add") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("cert-blob", "The PEM-formatted certificate blob").Required().StringVar(&c.certBlob) @@ -33,7 +32,6 @@ type CreateCommand struct { certBlob string id string - manifest manifest.Data name string } diff --git a/pkg/commands/tls/custom/certificate/delete.go b/pkg/commands/tls/custom/certificate/delete.go index cf2d6b912..42d4c379b 100644 --- a/pkg/commands/tls/custom/certificate/delete.go +++ b/pkg/commands/tls/custom/certificate/delete.go @@ -3,19 +3,18 @@ package certificate import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Destroy a TLS certificate. TLS certificates already enabled for a domain cannot be destroyed").Alias("remove") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS certificate").Required().StringVar(&c.id) @@ -27,8 +26,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/certificate/describe.go b/pkg/commands/tls/custom/certificate/describe.go index 1e4644a42..30f4e5d37 100644 --- a/pkg/commands/tls/custom/certificate/describe.go +++ b/pkg/commands/tls/custom/certificate/describe.go @@ -4,19 +4,18 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show a TLS certificate").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS certificate").Required().StringVar(&c.id) @@ -32,8 +31,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/certificate/list.go b/pkg/commands/tls/custom/certificate/list.go index 1055d051b..a9aa9e35f 100644 --- a/pkg/commands/tls/custom/certificate/list.go +++ b/pkg/commands/tls/custom/certificate/list.go @@ -4,22 +4,21 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) const emptyString = "" // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS certificates") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-not-after", "Limit the returned certificates to those that expire prior to the specified date in UTC").StringVar(&c.filterNotAfter) @@ -41,7 +40,6 @@ type ListCommand struct { filterNotAfter string filterTLSDomainID string include string - manifest manifest.Data pageNumber int pageSize int sort string diff --git a/pkg/commands/tls/custom/certificate/update.go b/pkg/commands/tls/custom/certificate/update.go index 3898de8be..42b45ca6b 100644 --- a/pkg/commands/tls/custom/certificate/update.go +++ b/pkg/commands/tls/custom/certificate/update.go @@ -3,19 +3,18 @@ package certificate import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Replace a TLS certificate with a newly reissued TLS certificate, or update a TLS certificate's name") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("cert-blob", "The PEM-formatted certificate blob").Required().StringVar(&c.certBlob) @@ -32,7 +31,6 @@ type UpdateCommand struct { certBlob string id string - manifest manifest.Data name string } diff --git a/pkg/commands/tls/custom/domain/domain_test.go b/pkg/commands/tls/custom/domain/domain_test.go index 280442192..029bee357 100644 --- a/pkg/commands/tls/custom/domain/domain_test.go +++ b/pkg/commands/tls/custom/domain/domain_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -52,8 +53,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/custom/domain/list.go b/pkg/commands/tls/custom/domain/list.go index 9c70f39a8..26572346a 100644 --- a/pkg/commands/tls/custom/domain/list.go +++ b/pkg/commands/tls/custom/domain/list.go @@ -4,22 +4,21 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) const emptyString = "" // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS domains") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-cert", "Limit the returned domains to those listed in the given TLS certificate's SAN list").StringVar(&c.filterTLSCertsID) @@ -43,7 +42,6 @@ type ListCommand struct { filterTLSCertsID string filterTLSSubsID string include string - manifest manifest.Data pageNumber int pageSize int sort string diff --git a/pkg/commands/tls/custom/privatekey/create.go b/pkg/commands/tls/custom/privatekey/create.go index f2568903d..c5172aee2 100644 --- a/pkg/commands/tls/custom/privatekey/create.go +++ b/pkg/commands/tls/custom/privatekey/create.go @@ -3,19 +3,18 @@ package privatekey import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("create", "Create a TLS certificate").Alias("add") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("key", "The contents of the private key. Must be a PEM-formatted key").Required().StringVar(&c.key) @@ -28,9 +27,8 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C type CreateCommand struct { cmd.Base - key string - manifest manifest.Data - name string + key string + name string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/privatekey/delete.go b/pkg/commands/tls/custom/privatekey/delete.go index 58aa8cfe3..8e80d2d7e 100644 --- a/pkg/commands/tls/custom/privatekey/delete.go +++ b/pkg/commands/tls/custom/privatekey/delete.go @@ -3,19 +3,18 @@ package privatekey import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Destroy a TLS private key. Only private keys not already matched to any certificates can be deleted").Alias("remove") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a private Key").Required().StringVar(&c.id) @@ -27,8 +26,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/privatekey/describe.go b/pkg/commands/tls/custom/privatekey/describe.go index 1ae37cc72..e6af1f1e1 100644 --- a/pkg/commands/tls/custom/privatekey/describe.go +++ b/pkg/commands/tls/custom/privatekey/describe.go @@ -4,19 +4,18 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show a TLS private key").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a private Key").Required().StringVar(&c.id) @@ -32,8 +31,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/custom/privatekey/list.go b/pkg/commands/tls/custom/privatekey/list.go index 6e4c7da31..2bc2882fa 100644 --- a/pkg/commands/tls/custom/privatekey/list.go +++ b/pkg/commands/tls/custom/privatekey/list.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS private keys") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-in-use", "Limit the returned keys to those without any matching TLS certificates").HintOptions("false").EnumVar(&c.filterInUse, "false") @@ -34,7 +33,6 @@ type ListCommand struct { cmd.JSONOutput filterInUse string - manifest manifest.Data pageNumber int pageSize int } diff --git a/pkg/commands/tls/custom/privatekey/privatekey_test.go b/pkg/commands/tls/custom/privatekey/privatekey_test.go index 84835b84d..16891f8c0 100644 --- a/pkg/commands/tls/custom/privatekey/privatekey_test.go +++ b/pkg/commands/tls/custom/privatekey/privatekey_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -63,8 +64,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -109,8 +110,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -163,8 +164,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -214,8 +215,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/platform/create.go b/pkg/commands/tls/platform/create.go index ae987c5bc..e13e449ae 100644 --- a/pkg/commands/tls/platform/create.go +++ b/pkg/commands/tls/platform/create.go @@ -3,19 +3,18 @@ package platform import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("upload", "Upload a new certificate") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("cert-blob", "The PEM-formatted certificate blob").Required().StringVar(&c.certBlob) @@ -36,7 +35,6 @@ type CreateCommand struct { certBlob string config []string intermediatesBlob string - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/platform/delete.go b/pkg/commands/tls/platform/delete.go index 512a2e994..a7be1ff92 100644 --- a/pkg/commands/tls/platform/delete.go +++ b/pkg/commands/tls/platform/delete.go @@ -3,19 +3,18 @@ package platform import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Destroy a certificate. This disables TLS for all domains listed as SAN entries").Alias("remove") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS bulk certificate").Required().StringVar(&c.id) @@ -27,8 +26,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/platform/describe.go b/pkg/commands/tls/platform/describe.go index 9c26bf759..cf91ca9da 100644 --- a/pkg/commands/tls/platform/describe.go +++ b/pkg/commands/tls/platform/describe.go @@ -4,19 +4,18 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Retrieve a single certificate").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS bulk certificate").Required().StringVar(&c.id) @@ -32,8 +31,7 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/platform/list.go b/pkg/commands/tls/platform/list.go index 0655f05db..91ac0cefb 100644 --- a/pkg/commands/tls/platform/list.go +++ b/pkg/commands/tls/platform/list.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all certificates") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-domain", "Optionally filter by the bulk attribute").StringVar(&c.filterTLSDomainID) @@ -35,7 +34,6 @@ type ListCommand struct { cmd.JSONOutput filterTLSDomainID string - manifest manifest.Data pageNumber int pageSize int sort string diff --git a/pkg/commands/tls/platform/platform_test.go b/pkg/commands/tls/platform/platform_test.go index 72219eed5..21bfc060c 100644 --- a/pkg/commands/tls/platform/platform_test.go +++ b/pkg/commands/tls/platform/platform_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -61,8 +62,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -107,8 +108,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -159,8 +160,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -208,8 +209,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -266,8 +267,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/platform/update.go b/pkg/commands/tls/platform/update.go index 2548eb75d..ce9549313 100644 --- a/pkg/commands/tls/platform/update.go +++ b/pkg/commands/tls/platform/update.go @@ -3,23 +3,20 @@ package platform import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand( - parent cmd.Registerer, g *global.Data, m manifest.Data, -) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command( "update", "Replace a certificate with a newly reissued certificate", ) c.Globals = g - c.manifest = m // Required. @@ -52,7 +49,6 @@ type UpdateCommand struct { certBlob string id string intermediatesBlob string - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/subscription/create.go b/pkg/commands/tls/subscription/create.go index 035be6b4a..b0a6f3ae9 100644 --- a/pkg/commands/tls/subscription/create.go +++ b/pkg/commands/tls/subscription/create.go @@ -3,11 +3,11 @@ package subscription import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) const emptyString = "" @@ -15,11 +15,10 @@ const emptyString = "" var certAuth = []string{"lets-encrypt", "globalsign"} // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("create", "Create a new TLS subscription").Alias("add") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("domain", "Domain(s) to add to the TLS certificates generated for the subscription (set flag once per domain)").Required().StringsVar(&c.domains) @@ -40,7 +39,6 @@ type CreateCommand struct { commonName string config string domains []string - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/subscription/delete.go b/pkg/commands/tls/subscription/delete.go index a2f5494bd..f84cd9e70 100644 --- a/pkg/commands/tls/subscription/delete.go +++ b/pkg/commands/tls/subscription/delete.go @@ -3,19 +3,18 @@ package subscription import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Destroy a TLS subscription. A subscription cannot be destroyed if there are domains in the TLS enabled state").Alias("remove") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS subscription").Required().StringVar(&c.id) @@ -30,9 +29,8 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D type DeleteCommand struct { cmd.Base - force cmd.OptionalBool - id string - manifest manifest.Data + force cmd.OptionalBool + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/subscription/describe.go b/pkg/commands/tls/subscription/describe.go index a10f6b625..229ad55f0 100644 --- a/pkg/commands/tls/subscription/describe.go +++ b/pkg/commands/tls/subscription/describe.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) var include = []string{"tls_authorizations", "tls_authorizations.globalsign_email_challenge"} // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show a TLS subscription").Alias("get") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS subscription").Required().StringVar(&c.id) @@ -35,9 +34,8 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - id string - include string - manifest manifest.Data + id string + include string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/tls/subscription/list.go b/pkg/commands/tls/subscription/list.go index dcd4d300a..9589423c6 100644 --- a/pkg/commands/tls/subscription/list.go +++ b/pkg/commands/tls/subscription/list.go @@ -4,22 +4,21 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) var states = []string{"pending", "processing", "issued", "renewing"} // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all TLS subscriptions") c.Globals = g - c.manifest = m // Optional. c.CmdClause.Flag("filter-active", "Limit the returned subscriptions to those that have currently active orders").BoolVar(&c.filterHasActiveOrder) @@ -43,7 +42,6 @@ type ListCommand struct { filterState string filterTLSDomainID string include string - manifest manifest.Data pageNumber int pageSize int sort string diff --git a/pkg/commands/tls/subscription/subscription_test.go b/pkg/commands/tls/subscription/subscription_test.go index 8ae798002..f600f46f3 100644 --- a/pkg/commands/tls/subscription/subscription_test.go +++ b/pkg/commands/tls/subscription/subscription_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -61,8 +62,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -107,8 +108,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -160,8 +161,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -210,8 +211,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -262,8 +263,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/tls/subscription/update.go b/pkg/commands/tls/subscription/update.go index 155dcda29..e983ee55e 100644 --- a/pkg/commands/tls/subscription/update.go +++ b/pkg/commands/tls/subscription/update.go @@ -3,19 +3,18 @@ package subscription import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Change the TLS domains or common name associated with this subscription, or update the TLS configuration for this set of domains") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS subscription").Required().StringVar(&c.id) @@ -38,7 +37,6 @@ type UpdateCommand struct { domains []string force cmd.OptionalBool id string - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/update/root.go b/pkg/commands/update/root.go index 03a76f404..3a9ed90d5 100644 --- a/pkg/commands/update/root.go +++ b/pkg/commands/update/root.go @@ -10,7 +10,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/filesystem" - "github.com/fastly/cli/pkg/github" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/revision" "github.com/fastly/cli/pkg/text" @@ -20,17 +19,13 @@ import ( // It should be installed under the primary root command. type RootCommand struct { cmd.Base - av github.AssetVersioner - configFilePath string } // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, configFilePath string, av github.AssetVersioner, g *global.Data) *RootCommand { +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { var c RootCommand c.Globals = g c.CmdClause = parent.Command("update", "Update the CLI to the latest version") - c.av = av - c.configFilePath = configFilePath return &c } @@ -47,7 +42,7 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { ) err = spinner.Process("Updating versioning information", func(_ *text.SpinnerWrapper) error { - current, latest, shouldUpdate = Check(revision.AppVersion, c.av) + current, latest, shouldUpdate = Check(revision.AppVersion, c.Globals.Versioners.CLI) return nil }) if err != nil { @@ -66,7 +61,7 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { var downloadedBin string err = spinner.Process("Fetching latest release", func(_ *text.SpinnerWrapper) error { - downloadedBin, err = c.av.DownloadLatest() + downloadedBin, err = c.Globals.Versioners.CLI.DownloadLatest() if err != nil { c.Globals.ErrLog.AddWithContext(err, map[string]any{ "Current CLI version": current, diff --git a/pkg/commands/user/create.go b/pkg/commands/user/create.go index d106438f7..2d65b001d 100644 --- a/pkg/commands/user/create.go +++ b/pkg/commands/user/create.go @@ -7,16 +7,14 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { var c CreateCommand c.CmdClause = parent.Command("create", "Create a user of the Fastly API and web interface").Alias("add") c.Globals = g - c.manifest = m // Required. c.CmdClause.Flag("login", "The login associated with the user (typically, an email address)").Action(c.login.Set).StringVar(&c.login.Value) @@ -31,7 +29,6 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C // CreateCommand calls the Fastly API to create an appropriate resource. type CreateCommand struct { cmd.Base - manifest manifest.Data login cmd.OptionalString name cmd.OptionalString diff --git a/pkg/commands/user/delete.go b/pkg/commands/user/delete.go index d59e988c2..1cfbb785b 100644 --- a/pkg/commands/user/delete.go +++ b/pkg/commands/user/delete.go @@ -7,16 +7,14 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, globals *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, globals *global.Data) *DeleteCommand { var c DeleteCommand c.CmdClause = parent.Command("delete", "Delete a user of the Fastly API and web interface").Alias("remove") c.Globals = globals - c.manifest = m c.CmdClause.Flag("id", "Alphanumeric string identifying the user").Required().StringVar(&c.id) return &c } @@ -25,8 +23,7 @@ func NewDeleteCommand(parent cmd.Registerer, globals *global.Data, m manifest.Da type DeleteCommand struct { cmd.Base - id string - manifest manifest.Data + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/user/describe.go b/pkg/commands/user/describe.go index 6ba6085f7..cfe4b9d07 100644 --- a/pkg/commands/user/describe.go +++ b/pkg/commands/user/describe.go @@ -9,15 +9,13 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Get a specific user of the Fastly API and web interface").Alias("get") c.Globals = g - c.manifest = m c.CmdClause.Flag("current", "Get the logged in user").BoolVar(&c.current) c.CmdClause.Flag("id", "Alphanumeric string identifying the user").StringVar(&c.id) c.RegisterFlagBool(c.JSONFlag()) // --json @@ -29,9 +27,8 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - current bool - id string - manifest manifest.Data + current bool + id string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/user/list.go b/pkg/commands/user/list.go index 6336517b9..402ddc198 100644 --- a/pkg/commands/user/list.go +++ b/pkg/commands/user/list.go @@ -9,16 +9,14 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List all users from a specified customer id") c.Globals = g - c.manifest = m c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagCustomerIDName, Description: cmd.FlagCustomerIDDesc, @@ -35,7 +33,6 @@ type ListCommand struct { cmd.JSONOutput customerID cmd.OptionalCustomerID - manifest manifest.Data } // Exec invokes the application logic for the command. diff --git a/pkg/commands/user/update.go b/pkg/commands/user/update.go index f9697be94..068ae92a8 100644 --- a/pkg/commands/user/update.go +++ b/pkg/commands/user/update.go @@ -8,16 +8,14 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Update a user of the Fastly API and web interface") c.Globals = g - c.manifest = m c.CmdClause.Flag("id", "Alphanumeric string identifying the user").StringVar(&c.id) c.CmdClause.Flag("login", "The login associated with the user (typically, an email address)").StringVar(&c.login) c.CmdClause.Flag("name", "The real life name of the user").StringVar(&c.name) @@ -31,12 +29,11 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U type UpdateCommand struct { cmd.Base - id string - login string - manifest manifest.Data - name string - reset bool - role string + id string + login string + name string + reset bool + role string } // Exec invokes the application logic for the command. diff --git a/pkg/commands/user/user_test.go b/pkg/commands/user/user_test.go index 0b3efcf36..dff1f93f1 100644 --- a/pkg/commands/user/user_test.go +++ b/pkg/commands/user/user_test.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -45,8 +46,8 @@ func TestCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -91,8 +92,8 @@ func TestDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -153,8 +154,8 @@ func TestDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -205,8 +206,8 @@ func TestList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -290,8 +291,8 @@ func TestUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/vcl/condition/condition_test.go b/pkg/commands/vcl/condition/condition_test.go index 0f7d34098..20ce9bf3f 100644 --- a/pkg/commands/vcl/condition/condition_test.go +++ b/pkg/commands/vcl/condition/condition_test.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -44,8 +45,8 @@ func TestConditionCreate(t *testing.T) { for _, testcase := range scenarios { t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -86,8 +87,8 @@ func TestConditionDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -137,8 +138,8 @@ func TestConditionUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -177,8 +178,8 @@ func TestConditionDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -245,8 +246,8 @@ func TestConditionList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/vcl/condition/create.go b/pkg/commands/vcl/condition/create.go index 16423d8ce..db9fa4c45 100644 --- a/pkg/commands/vcl/condition/create.go +++ b/pkg/commands/vcl/condition/create.go @@ -8,7 +8,6 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) @@ -19,7 +18,6 @@ var ConditionTypes = []string{"REQUEST", "CACHE", "RESPONSE", "PREFETCH"} // CreateCommand calls the Fastly API to create an appropriate resource. type CreateCommand struct { cmd.Base - manifest manifest.Data // Required. serviceVersion cmd.OptionalServiceVersion @@ -34,12 +32,11 @@ type CreateCommand struct { } // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a condition on a Fastly service version").Alias("add") @@ -63,7 +60,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -81,7 +78,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/condition/delete.go b/pkg/commands/vcl/condition/delete.go index 1cd433f3b..9158a6439 100644 --- a/pkg/commands/vcl/condition/delete.go +++ b/pkg/commands/vcl/condition/delete.go @@ -3,18 +3,17 @@ package condition import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // DeleteCommand calls the Fastly API to delete an appropriate resource. type DeleteCommand struct { cmd.Base - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -22,12 +21,11 @@ type DeleteCommand struct { } // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a condition on a Fastly service version").Alias("remove") @@ -48,7 +46,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -66,7 +64,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/condition/describe.go b/pkg/commands/vcl/condition/describe.go index 55e3e2e89..8112be201 100644 --- a/pkg/commands/vcl/condition/describe.go +++ b/pkg/commands/vcl/condition/describe.go @@ -9,25 +9,22 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // DescribeCommand calls the Fastly API to describe an appropriate resource. type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { var c DescribeCommand c.CmdClause = parent.Command("describe", "Show detailed information about a condition on a Fastly service version").Alias("get") c.Globals = g - c.manifest = m // Required flags c.CmdClause.Flag("name", "Name of condition").Short('n').Required().StringVar(&c.name) @@ -44,7 +41,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -66,7 +63,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/condition/list.go b/pkg/commands/vcl/condition/list.go index affc20eb2..98774aa59 100644 --- a/pkg/commands/vcl/condition/list.go +++ b/pkg/commands/vcl/condition/list.go @@ -4,12 +4,12 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // ListCommand calls the Fastly API to list appropriate resources. @@ -17,17 +17,15 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, data manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { var c ListCommand c.CmdClause = parent.Command("list", "List condition on a Fastly service version") c.Globals = g - c.manifest = data // Required flags c.RegisterFlag(cmd.StringFlagOpts{ @@ -41,7 +39,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, data manifest.Data) * c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -63,7 +61,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/condition/update.go b/pkg/commands/vcl/condition/update.go index 895fd8788..514ade8aa 100644 --- a/pkg/commands/vcl/condition/update.go +++ b/pkg/commands/vcl/condition/update.go @@ -9,14 +9,12 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // UpdateCommand calls the Fastly API to update an appropriate resource. type UpdateCommand struct { cmd.Base - manifest manifest.Data input fastly.UpdateConditionInput serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -30,11 +28,10 @@ type UpdateCommand struct { } // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, globals *global.Data, data manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { var c UpdateCommand c.CmdClause = parent.Command("update", "Update a condition on a Fastly service version") - c.Globals = globals - c.manifest = data + c.Globals = g // Required flags c.CmdClause.Flag("name", "Domain name").Short('n').Required().StringVar(&c.input.Name) @@ -59,7 +56,7 @@ func NewUpdateCommand(parent cmd.Registerer, globals *global.Data, data manifest c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -77,7 +74,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/custom/create.go b/pkg/commands/vcl/custom/create.go index b1545f6ed..1dfc30187 100644 --- a/pkg/commands/vcl/custom/create.go +++ b/pkg/commands/vcl/custom/create.go @@ -3,21 +3,20 @@ package custom import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Upload a VCL for a particular service and version").Alias("add") @@ -40,7 +39,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -60,7 +59,6 @@ type CreateCommand struct { autoClone cmd.OptionalAutoClone content cmd.OptionalString main cmd.OptionalBool - manifest manifest.Data name cmd.OptionalString serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -71,7 +69,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/custom/custom_test.go b/pkg/commands/vcl/custom/custom_test.go index 7a14df390..7c4ffd3a9 100644 --- a/pkg/commands/vcl/custom/custom_test.go +++ b/pkg/commands/vcl/custom/custom_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -159,8 +160,8 @@ func TestVCLCustomCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -238,8 +239,8 @@ func TestVCLCustomDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -303,8 +304,8 @@ func TestVCLCustomDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -372,8 +373,8 @@ func TestVCLCustomList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -486,8 +487,8 @@ func TestVCLCustomUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/vcl/custom/delete.go b/pkg/commands/vcl/custom/delete.go index c193306e4..4c546af25 100644 --- a/pkg/commands/vcl/custom/delete.go +++ b/pkg/commands/vcl/custom/delete.go @@ -3,21 +3,20 @@ package custom import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete the uploaded VCL for a particular service and version").Alias("remove") @@ -38,7 +37,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -56,7 +55,6 @@ type DeleteCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -67,7 +65,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/custom/describe.go b/pkg/commands/vcl/custom/describe.go index 2a2327ff1..c7457a537 100644 --- a/pkg/commands/vcl/custom/describe.go +++ b/pkg/commands/vcl/custom/describe.go @@ -4,20 +4,19 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the uploaded VCL for a particular service and version").Alias("get") @@ -35,7 +34,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type DescribeCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -68,7 +66,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/custom/list.go b/pkg/commands/vcl/custom/list.go index 4faa3d688..766635229 100644 --- a/pkg/commands/vcl/custom/list.go +++ b/pkg/commands/vcl/custom/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List the uploaded VCLs for a particular service and version") @@ -35,7 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/custom/update.go b/pkg/commands/vcl/custom/update.go index df0a8d5f0..18f9aa2fd 100644 --- a/pkg/commands/vcl/custom/update.go +++ b/pkg/commands/vcl/custom/update.go @@ -9,17 +9,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update the uploaded VCL for a particular service and version") @@ -42,7 +40,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -61,7 +59,6 @@ type UpdateCommand struct { autoClone cmd.OptionalAutoClone content cmd.OptionalString - manifest manifest.Data name string newName cmd.OptionalString serviceName cmd.OptionalServiceNameID @@ -73,7 +70,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/snippet/create.go b/pkg/commands/vcl/snippet/create.go index 6114e041e..fedd93951 100644 --- a/pkg/commands/vcl/snippet/create.go +++ b/pkg/commands/vcl/snippet/create.go @@ -3,24 +3,23 @@ package snippet import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // Locations is a list of VCL subroutines. var Locations = []string{"init", "recv", "hash", "hit", "miss", "pass", "fetch", "error", "deliver", "log", "none"} // NewCreateCommand returns a usable command registered under the parent. -func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand { +func NewCreateCommand(parent cmd.Registerer, g *global.Data) *CreateCommand { c := CreateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("create", "Create a snippet for a particular service and version").Alias("add") @@ -45,7 +44,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -67,7 +66,6 @@ type CreateCommand struct { content cmd.OptionalString dynamic cmd.OptionalBool location cmd.OptionalString - manifest manifest.Data name cmd.OptionalString priority cmd.OptionalInt serviceName cmd.OptionalServiceNameID @@ -79,7 +77,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/snippet/delete.go b/pkg/commands/vcl/snippet/delete.go index 911be7d8f..552d1acb9 100644 --- a/pkg/commands/vcl/snippet/delete.go +++ b/pkg/commands/vcl/snippet/delete.go @@ -3,21 +3,20 @@ package snippet import ( "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewDeleteCommand returns a usable command registered under the parent. -func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand { +func NewDeleteCommand(parent cmd.Registerer, g *global.Data) *DeleteCommand { c := DeleteCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("delete", "Delete a specific snippet for a particular service and version").Alias("remove") @@ -38,7 +37,7 @@ func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *D c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -56,7 +55,6 @@ type DeleteCommand struct { cmd.Base autoClone cmd.OptionalAutoClone - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -67,7 +65,7 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/snippet/describe.go b/pkg/commands/vcl/snippet/describe.go index ccc69fc0c..baf1b2ba0 100644 --- a/pkg/commands/vcl/snippet/describe.go +++ b/pkg/commands/vcl/snippet/describe.go @@ -9,16 +9,14 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" ) // NewDescribeCommand returns a usable command registered under the parent. -func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DescribeCommand { +func NewDescribeCommand(parent cmd.Registerer, g *global.Data) *DescribeCommand { c := DescribeCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("describe", "Get the uploaded VCL snippet for a particular service and version").Alias("get") @@ -37,7 +35,7 @@ func NewDescribeCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -57,7 +55,6 @@ type DescribeCommand struct { cmd.JSONOutput dynamic cmd.OptionalBool - manifest manifest.Data name string serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion @@ -73,7 +70,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/snippet/list.go b/pkg/commands/vcl/snippet/list.go index 2a1d1d830..3c1e22ca0 100644 --- a/pkg/commands/vcl/snippet/list.go +++ b/pkg/commands/vcl/snippet/list.go @@ -4,21 +4,20 @@ import ( "fmt" "io" + "github.com/fastly/go-fastly/v8/fastly" + "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" - "github.com/fastly/go-fastly/v8/fastly" ) // NewListCommand returns a usable command registered under the parent. -func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *ListCommand { +func NewListCommand(parent cmd.Registerer, g *global.Data) *ListCommand { c := ListCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("list", "List the uploaded VCL snippets for a particular service and version") @@ -35,7 +34,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -53,7 +52,6 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data serviceName cmd.OptionalServiceNameID serviceVersion cmd.OptionalServiceVersion } @@ -67,7 +65,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{ AllowActiveLocked: true, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/vcl/snippet/snippet_test.go b/pkg/commands/vcl/snippet/snippet_test.go index 6edc2f22d..bfd5062d1 100644 --- a/pkg/commands/vcl/snippet/snippet_test.go +++ b/pkg/commands/vcl/snippet/snippet_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/go-fastly/v8/fastly" "github.com/fastly/cli/pkg/app" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -193,8 +194,8 @@ func TestVCLSnippetCreate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -273,8 +274,8 @@ func TestVCLSnippetDelete(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -358,8 +359,8 @@ func TestVCLSnippetDescribe(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -427,8 +428,8 @@ func TestVCLSnippetList(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } @@ -571,8 +572,8 @@ func TestVCLSnippetUpdate(t *testing.T) { testcase := &scenarios[testcaseIdx] t.Run(testcase.Name, func(t *testing.T) { var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { - opts := testutil.NewRunOpts(testcase.Args, &stdout) + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { + opts := testutil.MockGlobalData(testcase.Args, &stdout) opts.APIClientFactory = mock.APIClient(testcase.API) return opts, nil } diff --git a/pkg/commands/vcl/snippet/update.go b/pkg/commands/vcl/snippet/update.go index fa9d444f4..b62c1c0a1 100644 --- a/pkg/commands/vcl/snippet/update.go +++ b/pkg/commands/vcl/snippet/update.go @@ -9,17 +9,15 @@ import ( "github.com/fastly/cli/pkg/cmd" fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" - "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" ) // NewUpdateCommand returns a usable command registered under the parent. -func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *UpdateCommand { +func NewUpdateCommand(parent cmd.Registerer, g *global.Data) *UpdateCommand { c := UpdateCommand{ Base: cmd.Base{ Globals: g, }, - manifest: m, } c.CmdClause = parent.Command("update", "Update a VCL snippet for a particular service and version") @@ -44,7 +42,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.RegisterFlag(cmd.StringFlagOpts{ Name: cmd.FlagServiceIDName, Description: cmd.FlagServiceIDDesc, - Dst: &c.manifest.Flag.ServiceID, + Dst: &g.Manifest.Flag.ServiceID, Short: 's', }) c.RegisterFlag(cmd.StringFlagOpts{ @@ -69,7 +67,6 @@ type UpdateCommand struct { content cmd.OptionalString dynamic cmd.OptionalBool location cmd.OptionalString - manifest manifest.Data name string newName cmd.OptionalString priority cmd.OptionalInt @@ -84,7 +81,7 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { AllowActiveLocked: c.dynamic.WasSet && c.dynamic.Value, AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, - Manifest: c.manifest, + Manifest: *c.Globals.Manifest, Out: out, ServiceNameFlag: c.serviceName, ServiceVersionFlag: c.serviceVersion, diff --git a/pkg/commands/version/root.go b/pkg/commands/version/root.go index e03485af6..5b72d78da 100644 --- a/pkg/commands/version/root.go +++ b/pkg/commands/version/root.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/cmd" "github.com/fastly/cli/pkg/github" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/revision" "github.com/fastly/cli/pkg/useragent" ) @@ -27,13 +28,15 @@ func init() { // It should be installed under the primary root command. type RootCommand struct { cmd.Base - viceroyVersioner github.AssetVersioner } // NewRootCommand returns a new command registered in the parent. -func NewRootCommand(parent cmd.Registerer, viceroyVersioner github.AssetVersioner) *RootCommand { - var c RootCommand - c.viceroyVersioner = viceroyVersioner +func NewRootCommand(parent cmd.Registerer, g *global.Data) *RootCommand { + c := RootCommand{ + Base: cmd.Base{ + Globals: g, + }, + } c.CmdClause = parent.Command("version", "Display version information for the Fastly CLI") return &c } @@ -43,7 +46,7 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error { fmt.Fprintf(out, "Fastly CLI version %s (%s)\n", revision.AppVersion, revision.GitCommit) fmt.Fprintf(out, "Built with %s\n", revision.GoVersion) - viceroy := filepath.Join(github.InstallDir, c.viceroyVersioner.BinaryName()) + viceroy := filepath.Join(github.InstallDir, c.Globals.Versioners.Viceroy.BinaryName()) // gosec flagged this: // G204 (CWE-78): Subprocess launched with variable // Disabling as we lookup the binary in a trusted location. For this to be a diff --git a/pkg/commands/version/version_test.go b/pkg/commands/version/version_test.go index 6ad86623d..2cdaa9077 100644 --- a/pkg/commands/version/version_test.go +++ b/pkg/commands/version/version_test.go @@ -12,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/github" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/testutil" ) @@ -67,15 +68,15 @@ func TestVersion(t *testing.T) { var stdout bytes.Buffer args := testutil.Args("version") - opts := testutil.NewRunOpts(args, &stdout) - opts.Versioners = app.Versioners{ + opts := testutil.MockGlobalData(args, &stdout) + opts.Versioners = global.Versioners{ Viceroy: github.New(github.Opts{ Org: "fastly", Repo: "viceroy", Binary: "viceroy", }), } - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err = app.Run(args, nil) diff --git a/pkg/commands/whoami/whoami_test.go b/pkg/commands/whoami/whoami_test.go index ed10c451f..0ba6e8c94 100644 --- a/pkg/commands/whoami/whoami_test.go +++ b/pkg/commands/whoami/whoami_test.go @@ -14,6 +14,7 @@ import ( "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/config" "github.com/fastly/cli/pkg/env" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/testutil" ) @@ -73,14 +74,14 @@ func TestWhoami(t *testing.T) { } { t.Run(testcase.name, func(t *testing.T) { var stdout bytes.Buffer - opts := testutil.NewRunOpts(testcase.args, &stdout) + opts := testutil.MockGlobalData(testcase.args, &stdout) opts.Env = testcase.env opts.HTTPClient = testcase.client - app.Init = func(_ []string, _ io.Reader) (app.RunOpts, error) { + app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { return opts, nil } err := app.Run(testcase.args, nil) - opts.ConfigFile = config.File{} + opts.Config = config.File{} t.Log(stdout.String()) testutil.AssertErrorContains(t, err, testcase.wantError) testutil.AssertStringContains(t, stdout.String(), testcase.wantOutput) diff --git a/pkg/global/doc.go b/pkg/global/doc.go index e81c1e744..08ccb9a68 100644 --- a/pkg/global/doc.go +++ b/pkg/global/doc.go @@ -1,2 +1,3 @@ -// Package global defines data structures that are used globally. +// Package global exposes a type to contain global'ish data. +// Effectively we use it to avoid an unfortunate import loop issue. package global diff --git a/pkg/global/global.go b/pkg/global/global.go index 889202c3f..2091fa25b 100644 --- a/pkg/global/global.go +++ b/pkg/global/global.go @@ -4,8 +4,10 @@ import ( "io" "github.com/fastly/cli/pkg/api" + "github.com/fastly/cli/pkg/auth" "github.com/fastly/cli/pkg/config" fsterr "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/github" "github.com/fastly/cli/pkg/lookup" "github.com/fastly/cli/pkg/manifest" ) @@ -16,6 +18,20 @@ const DefaultAPIEndpoint = "https://api.fastly.com" // DefaultAccountEndpoint is the default Fastly Accounts endpoint. const DefaultAccountEndpoint = "https://accounts.fastly.com" +// APIClientFactory creates a Fastly API client (modeled as an api.Interface) +// from a user-provided API token. It exists as a type in order to parameterize +// the Run helper with it: in the real CLI, we can use NewClient from the Fastly +// API client library via RealClient; in tests, we can provide a mock API +// interface via MockClient. +type APIClientFactory func(token, apiEndpoint string, debugMode bool) (api.Interface, error) + +// Versioners represents all supported versioner types. +type Versioners struct { + CLI github.AssetVersioner + Viceroy github.AssetVersioner + WasmTools github.AssetVersioner +} + // Data holds global-ish configuration data from all sources: environment // variables, config files, and flags. It has methods to give each parameter to // the components that need it, including the place the parameter came from, @@ -30,35 +46,46 @@ const DefaultAccountEndpoint = "https://accounts.fastly.com" // (e.g. an email address). Otherwise, parameters should be defined in specific // command structs, and parsed as flags. type Data struct { - // Env is all the data that is provided by the environment. - Env config.Environment + // APIClient is a Fastly API client instance. + APIClient api.Interface + // APIClientFactory is a factory function for creating an api.Interface type. + APIClientFactory APIClientFactory + // Args are the command line arguments provided by the user. + Args []string + // AuthServer is an instance of the authentication server type. + // Used for interacting with Fastly's SSO/OAuth authentication provider. + AuthServer auth.Runner // Config is an instance of the CLI configuration data. Config config.File // ConfigPath is the path to the CLI's application configuration. ConfigPath string + // Env is all the data that is provided by the environment. + Env config.Environment + // ErrLog provides an interface for recording errors to disk. + ErrLog fsterr.LogInterface // ExecuteWasmTools is a function that executes the wasm-tools binary. ExecuteWasmTools func(bin string, args []string) error // Flags are all the global CLI flags. Flags Flags - // Manifest is the fastly.toml manifest file. - Manifest manifest.Data + // HTTPClient is a HTTP client. + HTTPClient api.HTTPClient + // Input is the standard input for accepting input from the user. + Input io.Reader + // Manifest represents the fastly.toml manifest file and associated flags. + Manifest *manifest.Data + // Opener is a function that can open a browser window. + Opener func(string) error // Output is the output for displaying information (typically os.Stdout) Output io.Writer + // RTSClient is a Fastly API client instance for the Real Time Stats endpoints. + RTSClient api.RealtimeStatsInterface // SkipAuthPrompt is used to indicate to the `sso` command that the // interactive prompt can be skipped. This is for scenarios where the command // is executed directly by the user. SkipAuthPrompt bool - - // Custom interfaces - - // ErrLog provides an interface for recording errors to disk. - ErrLog fsterr.LogInterface - // APIClient is a Fastly API client instance. - APIClient api.Interface - // HTTPClient is a HTTP client. - HTTPClient api.HTTPClient - // RTSClient is a Fastly API client instance for the Real Time Stats endpoints. - RTSClient api.RealtimeStatsInterface + // Versioners contains multiple software versioning checkers. + // e.g. Check for latest CLI or Viceroy version. + Versioners Versioners } // Token yields the Fastly API token. diff --git a/pkg/testutil/args.go b/pkg/testutil/args.go index 14979c72a..d0a1f7f3f 100644 --- a/pkg/testutil/args.go +++ b/pkg/testutil/args.go @@ -7,12 +7,10 @@ import ( "strings" "time" - "github.com/hashicorp/cap/oidc" - - "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/auth" "github.com/fastly/cli/pkg/config" "github.com/fastly/cli/pkg/errors" + "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/runtime" @@ -58,11 +56,17 @@ func Args(args string) []string { // MockAuthServer is used to no-op the authentication server. type MockAuthServer struct { - auth.Starter + auth.Runner Result chan auth.AuthorizationResult } +// AuthURL returns a fully qualified authorization_endpoint. +// i.e. path + audience + scope + code_challenge etc. +func (s MockAuthServer) AuthURL() (string, error) { + return "", nil // no-op +} + // GetResult returns the results channel func (s MockAuthServer) GetResult() chan auth.AuthorizationResult { return s.Result @@ -78,20 +82,17 @@ func (s MockAuthServer) SetAPIEndpoint(_ string) { // no-op } -// SetVerifier sets the code verifier. -func (s MockAuthServer) SetVerifier(_ *oidc.S256Verifier) { - // no-op -} - // Start starts a local server for handling authentication processing. func (s MockAuthServer) Start() error { return nil // no-op } -// NewRunOpts returns a struct that can be used to populate a call to app.Run() +// MockGlobalData returns a struct that can be used to populate a call to app.Exec() // while the majority of fields will be pre-populated and only those fields // commonly changed for testing purposes will need to be provided. -func NewRunOpts(args []string, stdout io.Writer) app.RunOpts { +// +// TODO: Move this and other mocks into mocks package. +func MockGlobalData(args []string, stdout io.Writer) *global.Data { var md manifest.Data md.File.Args = args md.File.SetErrLog(errors.Log) @@ -103,11 +104,11 @@ func NewRunOpts(args []string, stdout io.Writer) app.RunOpts { configPath = "NUL" } - return app.RunOpts{ + return &global.Data{ Args: args, APIClientFactory: mock.APIClient(mock.API{}), AuthServer: &MockAuthServer{}, - ConfigFile: config.File{ + Config: config.File{ Profiles: TokenProfile(), }, ConfigPath: configPath, @@ -121,7 +122,7 @@ func NewRunOpts(args []string, stdout io.Writer) app.RunOpts { Opener: func(input string) error { return nil // no-op }, - Stdout: stdout, + Output: stdout, } }