cmd

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package cmd implements some basic use case 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

View Source
const (
	// EnvPrefix represents the prefix used to insure we have a reserved namespacce for cec specific ENV vars.
	EnvPrefix = "CEC"
)

Variables

View Source
var RootCmd = &cobra.Command{
	Use:                    os.Args[0],
	Short:                  "Connect to a Pydio Cells server using the command line",
	BashCompletionFunction: bashCompletionFunc,
	Args:                   cobra.MinimumNArgs(1),
	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.

CONFIGURE

  For the very first run, use '` + os.Args[0] + ` configure' 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 ` + confFileName + ` 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 ` + confFileName + ` 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) {

		needSetup := true

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

		parPath := viper.GetString("config")
		if parPath == "" {
			parPath = rest.DefaultConfigDirPath()
		}
		configFilePath = parPath + "/" + confFileName

		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()
			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 configure' first.\n", os.Args[0])
			}
		}
	},

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

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.

Functions

func ClearConfig added in v2.2.0

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