cmd

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	API          = "api"
	ClientId     = "client_id"
	ClientSecret = "client_secret"
)

Variables

View Source
var ApiHostToUrlMap = map[string]string{
	"api.moltin.com":             "https://euwest.cm.elasticpath.com/",
	"useast.api.elasticpath.com": "https://useast.cm.elasticpath.com/",
}
View Source
var DeleteAll = &cobra.Command{
	Use:    "delete-all [RESOURCE] [ID_1] [ID_2]",
	Short:  "Deletes all of a resource.",
	Args:   cobra.MinimumNArgs(1),
	Hidden: true,
	RunE: func(cmd *cobra.Command, args []string) error {

		resource, ok := resources.GetResourceByName(args[0])
		if !ok {
			return fmt.Errorf("Could not find resource %s", args[0])
		}

		if resource.GetCollectionInfo == nil {
			return fmt.Errorf("Resource %s doesn't support GET collection", args[0])
		}

		if resource.DeleteEntityInfo == nil {
			return fmt.Errorf("Resource %s doesn't support DELETE", args[0])
		}

		min := resource.DeleteEntityInfo.MinResources

		delName := resource.SingularName

		ids, err := getPage(args[0])
		if err != nil {
			return fmt.Errorf("Problem getting page of ids for resource %s", args[0])
		}

		for len(ids) > min {
			delPage(delName, ids)
			ids, err = getPage(args[0])
			if err != nil {
				return fmt.Errorf("Problem getting page of ids for resource %s", args[0])
			}
		}

		return nil
	},

	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) == 0 {
			return completion.Complete(completion.Request{
				Type: completion.CompletePluralResource,
				Verb: completion.Delete,
			})
		}

		return []string{}, cobra.ShellCompDirectiveNoFileComp
	},
}
View Source
var Logs = &cobra.Command{Use: "logs", Short: "Retrieve information about previous requests"}
View Source
var LogsClear = &cobra.Command{
	Use:   "clear",
	Short: "Clears all HTTP request and response logs",
	RunE: func(cmd *cobra.Command, args []string) error {
		return profiles.ClearAllRequestLogs()
	},
}
View Source
var LogsList = &cobra.Command{
	Use:   "list",
	Short: "List all HTTP logs",
	RunE: func(cmd *cobra.Command, args []string) error {
		files, err := profiles.GetAllRequestLogTitles()
		if err != nil {
			return err
		}

		for idx, name := range files {
			fmt.Printf("%d %s\n", idx, name)
		}
		return nil
	},
}
View Source
var LogsShow = &cobra.Command{
	Use:   "show <NUMBER>",
	Short: "Show HTTP logs for specific number",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {

		i, err := strconv.Atoi(args[0])

		if err != nil {
			return fmt.Errorf("Could not get the %s entry => %w", args[0], err)
		}

		content, err := profiles.GetNthRequestLog(i)

		if err != nil {
			return fmt.Errorf("Couldn't print logs: %v", err)
		}

		fmt.Println(content)

		return nil
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   os.Args[0],
	Short: "A command line interface for interacting with the Elastic Path Commerce Cloud API",
	Long: `The EPCC CLI tool provides a powerful command line interface for interacting with the Elastic Path Commerce Cloud API.

The EPCC CLI tool uses environment variables for configuration and in particular a tool like https://direnv.net/ which
auto populates your shell with environment variables when you switch directories. This allows you to store a context in a folder,
and come back to it at any time.

Environment Variables

- EPCC_API_BASE_URL - The API endpoint that we will hit
- EPCC_CLIENT_ID - The client id (available in Commerce Manager)
- EPCC_CLIENT_SECRET - The client secret (available in Commerce Manager)
- EPCC_BETA_API_FEATURES - Beta features in the API we want to enable.
`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		log.SetLevel(logger.Loglevel)

		for _, runFunc := range persistentPreRunFuncs {
			err := runFunc(cmd, args)
			if err != nil {
				return err
			}
		}

		return nil
	},

	SilenceUsage: true,
	Version:      fmt.Sprintf("%s (Commit %s)", version.Version, version.Commit),
}

Functions

func AddRootPreRunFunc added in v0.6.0

func AddRootPreRunFunc(f func(cmd *cobra.Command, args []string) error)

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL