cmd

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Overview

Package cmd implements basic use cases to manage your files on your remote server via the command line of your local workstation or any server you can access with SSH. It also demonstrates what can be achieved when combining the use of the Go SDK for Cells with the powerful Cobra framework to implement CLI client applications for Cells.

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:                    os.Args[0],
	Short:                  "Connect to a Pydio Cells server using the command line",
	BashCompletionFunction: bashCompletionFunc,

	Long: `
DESCRIPTION

  This command line client allows interacting with a Pydio Cells server via the command line. 
  It uses the Cells SDK for Go and the REST API under the hood.

  See the respective help pages of the various commands to get detailed explanation and some examples.

  *WARNING*: cec v4 only supports remote servers that are in v4 or newer. 

CONFIGURE

  For the very first run, use '` + os.Args[0] + ` config add' to begin the command-line based configuration wizard. 
  This will guide you through a quick procedure to get you up and ready in no time.

  Non-sensitive information are stored by default in a ` + common.DefaultConfigFileName + ` file under ` + rest.DefaultConfigDirPath() + `
  You can change this location by using the --config flag.
  Entered (or retrieved, in the case of OAuth2 procedure) credentials will be stored in your keyring.

  [Note]: if no keyring is found, all information are stored in clear text in the ` + common.DefaultConfigFileName + ` file, including sensitive bits.

ENVIRONMENT

  All the command flags documented below are mapped to their associated ENV var, using upper case and CEC_ prefix.

  For example:
    $ ` + os.Args[0] + ` ls --no_cache
  is equivalent to: 
    $ export CEC_NO_CACHE=true; ` + os.Args[0] + ` ls
   
  This is typically useful when using the Cells Client non-interactively on a server:
    $ export CEC_URL=https://files.example.com; export CEC_TOKEN=<Your Personal Access Token>; 
    $ ` + os.Args[0] + ` ls

`, PersistentPreRun: func(cmd *cobra.Command, args []string) {

		if len(os.Args) == 1 {
			return
		}

		needSetup := true

		for _, skip := range infoCommands {
			if os.Args[1] == skip {
				needSetup = false
				break
			}
		}

		parPath := viper.GetString("config")
		if parPath == "" {
			parPath = rest.DefaultConfigDirPath()
		}
		configFilePath = filepath.Join(parPath, common.DefaultConfigFileName)

		tmpURLStr := viper.GetString("url")
		if tmpURLStr != "" {
			// Also sanitize the passed URL
			var err error
			serverURL, err = rest.CleanURL(tmpURLStr)
			if err != nil {
				log.Fatalf("server URL %s seems to be unvalid, please double check and adapt. Cause: %s", tmpURLStr, err.Error())
			}
		}
		authType = viper.GetString("auth_type")
		token = viper.GetString("token")
		login = viper.GetString("login")
		password = viper.GetString("password")
		noCache = viper.GetBool("no_cache")
		skipKeyring = viper.GetBool("skip_keyring")
		skipVerify = viper.GetBool("skip_verify")

		if needSetup {
			e := setUpEnvironment(cmd.Context())
			if e != nil {
				if !os.IsNotExist(e) {
					log.Fatalf("unexpected error during initialisation phase: %s", e.Error())
				}

				log.Fatalf("No configuration has been found, please make sure to run '%s config add' first.\n", os.Args[0])
			}
		}
	},

	Run: func(cmd *cobra.Command, args []string) {
		cmd.Usage()
	},
}

RootCmd is the parent of all commands defined in this package. It takes care of the pre-configuration of the default connection to the SDK in its PersistentPreRun phase.

View Source
var ToolsCmd = &cobra.Command{
	Use:    "tools",
	Short:  "Additional tools",
	Hidden: true,
	Long: `
DESCRIPTION

  Various additional useful helper commands.
`,
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

ToolsCmd are tools that do not need a valid connection to a remote running Cells instance

Functions

func ClearConfig

func ClearConfig() error

Types

This section is empty.

Jump to

Keyboard shortcuts

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