cmd

package
v5.0.0-alpha04 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 56 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

View Source
const (
	EnvDisplayHiddenFlags = "CEC_DISPLAY_HIDDEN_FLAGS"
)
View Source
const (
	PydioSystemUser string = "pydio.system.user"
)

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
		}

		logger, err := configureLogger(viper.GetString("log"))
		if err != nil {
			log.Fatalf("could not initialize logger: %v, aborting.", err)
		}
		defer func(logger *zap.Logger) {
			_ = logger.Sync()
		}(logger)

		needSetup := true
		for _, skip := range infoCommands {

			if os.Args[1] == skip || (len(os.Args) > 2 && os.Args[2] == 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 != "" {

			serverURL, err = rest.CleanURL(tmpURLStr)
			if err != nil {
				rest.Log.Fatalf("server URL %s seems to be un-valid, please double check and adapt. Cause: %s", tmpURLStr, err.Error())
			}
		}

		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 viper.GetBool("no_cache") {
			noCache = true
		}
		if viper.GetBool("skip_keyring") {
			skipKeyring = true
		}
		if viper.GetBool("skip_verify") {
			skipVerify = true
		}

		if needSetup {
			e := setUpEnvironment(cmd.Context())
			if e != nil {
				if !os.IsNotExist(e) {
					rest.Log.Fatalf("unexpected error during initialisation phase: %s", e.Error())
				}
				rest.Log.Fatalf("no configuration has been found, please make sure to run '%s config add' first", os.Args[0])
			}
		}
	},

	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Usage()
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		if sdkClient != nil {
			sdkClient.Teardown()
		}
	},
}

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.Usage()
	},
}

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

Functions

func ClearConfig

func ClearConfig() error

func CurrentSdkClient

func CurrentSdkClient() *rest.SdkClient

func RegisterExtraOfflineCommand

func RegisterExtraOfflineCommand(commands ...string)

RegisterExtraOfflineCommand adds the passed commands to the list of commands that skip the verifications that ensure that we have a valid connection to a distant Cells server defined.

Types

type FilterCondition

type FilterCondition struct {
	Operator string `json:"op"`
	Value    any    `json:"value"`
}

type FilterMap

type FilterMap map[string]FilterCondition

type Result

type Result struct {
	JobID    string
	JobLabel string
	Result   string
}

Jump to

Keyboard shortcuts

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