cli

package
v0.4.80 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: BSD-3-Clause Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const SOCKSProxyEnv = "SOCKS_PROXY"

SOCKSProxyEnv is the environment variable consulted by FileLoader (and WrapLoaderWithSOCKS5) to configure an outbound SOCKS5 proxy for iRODS connections. The value can either be a bare host:port pair or a fully qualified socks5:// (or socks5h://) URL with optional user:password credentials.

Variables

View Source
var (
	Reset     = "\033[00m"
	Red       = "\033[31m"
	Green     = "\033[32m"
	Yellow    = "\033[33m"
	Blue      = "\033[34m"
	Magenta   = "\033[35m"
	Cyan      = "\033[36m"
	Gray      = "\033[37m"
	LightGray = "\033[38m"
	White     = "\033[97m"
	NoColor   = "\033[39m"
	Bold      = "\033[01m"
	NoBold    = "\033[22m"

	HeaderBackground = "\033[48;5;6m"
	RowBackground    = "\033[48;5;14m"
	AltRowBackground = "\033[48;5;111m" // 153,111  81,117
	NoBackground     = "\033[49m"

	Underline   = "\033[4m"
	NoUnderline = "\033[24m"
)
View Source
var ArgumentRE = regexp.MustCompile("(<[a-zA-Z0-9 _-]+>)")
View Source
var ErrAmbiguousTarget = errors.New("ambiguous command, please specify a target collection or directory with a trailing slash")

Functions

func ApplyFileAuth added in v0.4.69

func ApplyFileAuth(ctx context.Context, file string, env *iron.Env)

ApplyFileAuth applies the file-based authentication state to env, mirroring what FileLoader does internally. It tries to read a cached password from the .irodsA file (or the file specified by IRODS_AUTHENTICATION_FILE) next to the irods_environment.json path, switching env.AuthScheme to "native" on success. For pam_interactive it configures a PersistentState backed by the .irodsA.json file in the same directory, so that subsequent runs can re-use the cached PAM token instead of prompting again.

This is exported so callers that reload or modify env after the initial Loader call (e.g. an interactive UI that lets the user change AuthScheme) can re-apply the auth file logic against the modified env.

func Fprintcolorln added in v0.4.41

func Fprintcolorln(w io.Writer, color string, args ...any)

func GetWorkdirFromFile added in v0.4.4

func GetWorkdirFromFile(file string) (string, error)

GetWorkdirFromFile returns the working directory as stored in an irods environment file. The file is expected to have been created with the iRODS `icd` command.

func GetZone added in v0.4.0

func GetZone(arg string, t ArgType) string

func Name added in v0.4.0

func Name(path string) string

func ReadAuthFile added in v0.4.0

func ReadAuthFile(authFile string, uid *int) (string, error)

ReadAuthFile reads the contents of a file and decodes it according to the iRODS scramble algorithm. If no uid is given, the uid of the file is used to decode the contents. The file is expected to have been created with the iRODS `iinit` command.

func SkipInit added in v0.4.0

func SkipInit(cmd *cobra.Command) bool

func StoreWorkdirInFile added in v0.4.4

func StoreWorkdirInFile(ctx context.Context, file, workdir string) error

StoreWorkdirInFile stores the working directory in an irods environment file. The file is expected to have been created with the iRODS `icd` command.

func WriteAuthFile added in v0.4.4

func WriteAuthFile(authFile, password string, uid *int) error

WriteAuthFile writes the given password to a file using the iRODS scramble algorithm. The file is expected to be the .irodsA file used by the iinit command. The file is created if it doesn't exist, and the permissions are set to 0600. If the file is already present, the content is overwritten. The uid of the file owner is used to encode the password.

Types

type App

type App struct {
	*iron.Client

	Admin          bool
	Debug          int
	Native         bool
	Workdir        string
	PamTTL         time.Duration
	NonInteractive bool

	// Prompt overrides the iron.Prompt used during authentication. When
	// nil, Init falls back to iron.Bot{} for NonInteractive runs and to
	// iron.StdPrompt otherwise (the default chosen by iron.New).
	Prompt iron.Prompt
	// contains filtered or unexported fields
}

func New

func New(_ context.Context, options ...Option) *App

func (*App) ArgTypes added in v0.4.9

func (a *App) ArgTypes(cmd *cobra.Command) []ArgType

func (*App) CheckUpdate added in v0.4.18

func (a *App) CheckUpdate(ctx context.Context)

func (*App) Close

func (a *App) Close() error

func (*App) Command

func (a *App) Command() *cobra.Command

func (*App) CompleteArgs added in v0.4.0

func (a *App) CompleteArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteArgs implements shell completion for the given command and arguments. It tries to find the zone of the previous arguments and detect the argument type of the last given argument. If the zone cannot be determined, or if there are at least two different zones involved in the arguments, it returns a default directive. See completeArgument for the actual completion logic.

func (*App) ConfigStore added in v0.4.69

func (a *App) ConfigStore() ConfigStore

ConfigStore returns the configured ConfigStore, or nil if none.

func (*App) ConfigStoreArgs added in v0.4.69

func (a *App) ConfigStoreArgs() []string

ConfigStoreArgs returns the positional argument labels expected by the ConfigStore (e.g. ["user name", "zone name", "host"]). Returns nil if no ConfigStore is configured.

func (*App) Exec added in v0.4.69

func (a *App) Exec(ctx context.Context, stdout, stderr io.Writer, args ...string) error

Exec runs a single iron CLI command (e.g. "mkdir", "-p", "/zone/home/peter") against the App's already-initialized Client. It is intended for embedding callers (such as iron-gui) that drive the App outside of cobra. The command's stdout / stderr are routed to the supplied writers (nil falls back to os.Stdout / os.Stderr). The App.Client must already be set.

func (*App) Init added in v0.4.0

func (a *App) Init(ctx context.Context, zone string) error

Init loads the iRODS environment for the given zone (empty string = the Loader's default) and constructs the underlying iron.Client. It is the cobra-independent core of Init: callers that drive the App outside of cobra (e.g. iron-gui) can use it directly. Stamp the context with ForceReauthentication=true to bypass cached credentials.

On failure, returns InitError wrapping the underlying error (and any partially-loaded env, when available). On success, App.Client is set and App.Workdir is defaulted if it was empty.

func (*App) LatestVersion added in v0.4.18

func (a *App) LatestVersion(ctx context.Context) (*semver.Version, error)

func (*App) Loader added in v0.4.69

func (a *App) Loader() Loader

Loader returns the configured environment Loader, or nil if none.

func (*App) Name added in v0.4.69

func (a *App) Name() string

Name returns the application name (used for client telemetry, prompts, etc.).

func (*App) PasswordStore added in v0.4.69

func (a *App) PasswordStore() PasswordStore

PasswordStore returns the configured PasswordStore, or nil if none.

func (*App) Path added in v0.4.0

func (a *App) Path(path string) string

func (*App) PathIn added in v0.4.35

func (a *App) PathIn(path, workdir string) string

func (*App) PreRun added in v0.4.69

func (a *App) PreRun(cmd *cobra.Command, args []string) error

PreRun sets up the client for most commands. It is used under the PersistentPreRunE hook. To override, either adjust SkipInit or implement your own PersistentPreRunE hook.

func (*App) PreRunAuth added in v0.4.69

func (a *App) PreRunAuth(cmd *cobra.Command, args []string) error

PreRunAuth sets up the client for the "auth" command. It ensures a previous client is closed, useful for the shell.

func (*App) PreRunAuthConfigStore added in v0.4.69

func (a *App) PreRunAuthConfigStore(cmd *cobra.Command, args []string) error

PreRunAuthConfigStore sets up the client for the "auth" command, in case two or more arguments are provided and a ConfigStore is configured.

func (*App) PreRunShell added in v0.4.69

func (a *App) PreRunShell(cmd *cobra.Command, args []string) error

PreRunShell calls PreRun but does not fail on error, instead it writes an invitation to authenticate. Useful for the shell only.

func (*App) ResetClient added in v0.4.29

func (a *App) ResetClient() error

ResetClient closes the client and sets it to nil This is used for the shell in combination with the "auth" command, to switch between zones.

func (*App) Update added in v0.4.18

func (a *App) Update(ctx context.Context, path string, allowDowngrade bool) error

func (*App) Version added in v0.4.18

func (a *App) Version() *semver.Version

type ArgType added in v0.4.0

type ArgType int
const (
	Unknown ArgType = iota
	ObjectPath
	CollectionPath
	Path       // object or collection
	TargetPath // object or collection
	LocalFile
	LocalDirectory
	Zone
)

type ConfigStore added in v0.4.9

type ConfigStore func(ctx context.Context, args []string) (string, error)

ConfigStore is a function that can store an iRODS environment e.g. to a file, based on CLI parameters to generate the configuration. The function must return the configured zone or an error. The returned zone name will subsequentially be passed to the Loader, and using the resulting iRODS environment, a first iRODS connection can be established. Lastly, the password will be persisted using the PasswordStore function.

func FileStore added in v0.4.9

func FileStore(file string, template iron.Env) ConfigStore

type ContextKey added in v0.4.4

type ContextKey string
var ForceReauthentication ContextKey = "force_reauthentication"

type InitError added in v0.4.29

type InitError struct {
	App *App
	Env iron.Env
	Err error
}

func (InitError) Error added in v0.4.29

func (e InitError) Error() string

type JSONPrinter added in v0.4.0

type JSONPrinter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

func (*JSONPrinter) Flush added in v0.4.0

func (jp *JSONPrinter) Flush()

func (*JSONPrinter) Print added in v0.4.0

func (jp *JSONPrinter) Print(name string, i api.Record)

func (*JSONPrinter) Setup added in v0.4.24

func (jp *JSONPrinter) Setup(hasACL, hasMeta, _, hasReplicas bool)

type Loader added in v0.4.0

type Loader func(ctx context.Context, zone string) (iron.Env, iron.DialFunc, error)

Loader is a function that loads an iRODS environment e.g. from a file. The requested zone will be autodetected from the command, if possible, and can be used by the loader in a multi-zone environments to determine the right connection parameters. If no zone can be detected, an empty string is passed. In this case, the Loader might fall back to a default zone, or return ErrZoneRequired.

func FileLoader added in v0.4.0

func FileLoader(file string) Loader

FileLoader loads an irods environment from a file and returns a Loader. The environment is loaded from the file, and the password is read from the .irodsA file in the same directory, or the file specified by the IRODS_AUTHENTICATION_FILE environment variable if set.

If the SOCKS_PROXY environment variable is set, the returned Loader's DialFunc routes iRODS connections through that SOCKS5 proxy. See WrapLoaderWithSOCKS5 for the accepted proxy URL formats.

func WrapLoaderWithSOCKS5 added in v0.4.71

func WrapLoaderWithSOCKS5(loader Loader, proxyURL string) Loader

WrapLoaderWithSOCKS5 returns a Loader that routes connections through the given SOCKS5 proxy. If proxyURL is empty, loader is returned unchanged. The proxyURL accepts the same forms as the SOCKS_PROXY environment variable: a bare host:port (socks5:// is assumed) or a full socks5://[user:pass@]host:port URL.

type Option added in v0.4.0

type Option func(*App)

func WithCommandHook added in v0.4.76

func WithCommandHook(hook func(*cobra.Command, bool)) Option

func WithConfigStore added in v0.4.9

func WithConfigStore(store ConfigStore, argLabels []string) Option

WithConfigStore returns an Option that configures an App with a ConfigStore and positional arguments for the store. The ConfigStore is used to store the iRODS environment configuration, and the positional arguments are used to generate and parse the CLI command. At least 2 arguments are expected.

func WithDefaultWorkdir added in v0.4.3

func WithDefaultWorkdir(workdir string) Option

WithDefaultWorkdir sets the default working directory for the App. This option is used to specify the default working directory when creating a new App. The default working directory is used when the user does not specify a working directory when running commands.

func WithDefaultWorkdirFromFile added in v0.4.4

func WithDefaultWorkdirFromFile(file string) Option

func WithLoader added in v0.4.0

func WithLoader(loader Loader) Option

WithLoader sets the Loader for the App, which is used to load the environment from a file, or other source.

func WithName added in v0.4.0

func WithName(name string) Option

WithName sets the name of the App. This name is used to generate the name of the command line tool when running the App. The name is used to generate the command line tool help text and to generate the command line tool completion. The name is also used to generate the configuration file name when persisting the App's configuration.

func WithPasswordStore added in v0.4.4

func WithPasswordStore(store PasswordStore) Option

WithPasswordStore sets the password store function for the App. This function is used to store the password for the iRODS environment after the user has authenticated with the environment. The password store function is called with the password and the App's context. The password store function is expected to store the password securely and to be able to retrieve the password later.

func WithUpdater added in v0.4.19

func WithUpdater(updater *selfupdate.Updater, repo selfupdate.RepositorySlug) Option

func WithVersion added in v0.4.20

func WithVersion(version string) Option

WithVersion sets the version for the App.

type PasswordStore added in v0.4.4

type PasswordStore func(ctx context.Context, env iron.Env, password string) error

PasswordStore is a function that can persist an irods password, if wanted, for use in subsequent commands.

func FilePasswordStore added in v0.4.4

func FilePasswordStore(file string) PasswordStore

type Printer added in v0.4.0

type Printer interface {
	Setup(hasACL, hasMeta, hasCollectionSize, hasReplicas bool)
	Print(name string, i api.Record)
	Flush()
}

type TablePrinter added in v0.4.0

type TablePrinter struct {
	Writer interface {
		io.Writer
		Flush() error
	}
	Zone string
	// contains filtered or unexported fields
}

func (*TablePrinter) Flush added in v0.4.0

func (tp *TablePrinter) Flush()

func (*TablePrinter) Print added in v0.4.0

func (tp *TablePrinter) Print(name string, i api.Record)

func (*TablePrinter) Setup added in v0.4.24

func (tp *TablePrinter) Setup(hasACL, hasMeta, hasCollectionSizes, hasReplicas bool)

type WorkdirStore added in v0.4.4

type WorkdirStore func(ctx context.Context, workdir string) error

WorkdirStore is a function that can persist a workdir, if wanted, for use in subsequent commands.

Jump to

Keyboard shortcuts

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