cli

package
v0.0.0-...-9bcff37 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package cli implements the command-line interface for proton-cli.

Index

Constants

View Source
const (
	Version    = "0.0.1"
	AppVersion = "web-drive@5.2.0"
	UserAgent  = "ProtonCLI/v0.1.0"
	APIHost    = "https://drive-api.proton.me"
)

Application constants unique to proton-cli.

Variables

This section is empty.

Functions

func AddCommand

func AddCommand(cmd *cobra.Command)

AddCommand registers a subcommand with the root command.

func BoolFlag

func BoolFlag(fs *pflag.FlagSet, p *bool, name string, value bool, usage string)

BoolFlag registers a boolean flag that does NOT require an argument. Uses BoolFunc internally so that --flag (without =true) works correctly. This works around optargs/pflag's BoolVar having BoolTakesArg()=true.

func BoolFlagP

func BoolFlagP(fs *pflag.FlagSet, p *bool, name, shorthand string, value bool, usage string)

BoolFlagP is like BoolFlag but accepts a shorthand letter.

func ConfigFilePath

func ConfigFilePath() string

ConfigFilePath returns the resolved config file path.

func Execute

func Execute()

Execute runs the root command and exits on error.

func InstallDebugHooks

func InstallDebugHooks(m *proton.Manager)

InstallDebugHooks adds pre-request and post-response logging hooks to the proton manager. Called when verbosity >= 3.

func NewDriveClient

func NewDriveClient(ctx context.Context, session *common.Session) (*drive.Client, error)

NewDriveClient creates a drive client from a session and applies config from RuntimeContext.

func RegisterProfileFlag

func RegisterProfileFlag()

RegisterProfileFlag is a no-op when built without the profile tag.

func SetContext

func SetContext(cmd *cobra.Command, rc *RuntimeContext)

SetContext stores a RuntimeContext on the cobra command's context.

func SetServiceCmd

func SetServiceCmd(cmd *cobra.Command, service string)

SetServiceCmd configures the service context on a command. Subcommands call this to set the service name, session store, and Proton options on RuntimeContext.

func SetupSession

func SetupSession(ctx context.Context, cmd *cobra.Command) (*common.Session, error)

SetupSession returns a fully initialized, ready-to-use session by reading all per-invocation state from RuntimeContext. It calls api/account/ restore primitives, sets BaseURL/AppVersion/UserAgent, loads config onto Session.Config, and returns a ready session.

When RuntimeContext.ServiceName is set to a specific service (not "*"), it uses RestoreServiceSession which handles auto-forking from the account session.

func StartProfile

func StartProfile() func()

StartProfile is a no-op when built without the profile tag.

func UserPrompt

func UserPrompt(prompt string, password bool) (string, error)

UserPrompt prompts the user for input. If password is true, echo is disabled while reading.

Types

type AccountEntry

type AccountEntry struct {
	Username string            `json:"username"`
	Sessions map[string]string `json:"sessions"` // service name → UUID
}

AccountEntry represents a single account in the session index.

type Keyring

type Keyring interface {
	Get(service, account string) (string, error)
	Set(service, account, password string) error
	Delete(service, account string) error
}

Keyring abstracts system keyring operations for testing.

type RuntimeContext

type RuntimeContext struct {
	// Timeout is the global request timeout duration (from --timeout).
	Timeout time.Duration

	// DebugHTTP is true when verbosity >= 3, enabling HTTP debug logging.
	DebugHTTP bool

	// ProtonOpts holds the base Proton API options (host, app version, user agent).
	ProtonOpts []proton.Option

	// SessionStore handles loading/saving session data for the current service.
	SessionStore common.SessionStore

	// AccountStore handles loading/saving the account session data.
	// Used by RestoreServiceSession as the fork source.
	AccountStore common.SessionStore

	// CookieStore handles loading/saving cookie-based session data.
	CookieStore common.SessionStore

	// Account holds the current --account flag value.
	Account string

	// ServiceName holds the current service context ("drive", "lumo", "account", or "*").
	ServiceName string

	// AppVersionOverride holds the --app-version flag value.
	AppVersionOverride string

	// Config holds the loaded application config.
	Config *config.Config

	// SessionFile is the resolved path to the sessions.db file.
	SessionFile string

	// Verbose is the -v count from the root command. 0 = default (short IDs),
	// >= 1 = verbose output (full IDs, extra detail).
	Verbose int
}

RuntimeContext bundles the per-invocation state that was previously spread across package-level variables. Stored on the cobra command context by PersistentPreRunE, retrieved by subcommands via GetContext.

func GetContext

func GetContext(cmd *cobra.Command) *RuntimeContext

GetContext retrieves the RuntimeContext from a cobra command's context. It walks up the parent chain because PersistentPreRunE sets the context on the root command, not on the executing subcommand. Returns nil if no RuntimeContext has been set (e.g. PersistentPreRunE has not run).

type SessionIndex

type SessionIndex struct {
	// contains filtered or unexported fields
}

SessionIndex manages the on-disk session index file and keyring lookups. It maps (account, service) pairs to UUIDs stored in the index file, while actual secrets live in the system keyring keyed by those UUIDs.

func NewSessionStore

func NewSessionStore(path string, account string, service string, kr Keyring) *SessionIndex

NewSessionStore returns a SessionIndex for the given account and service. The path is the filesystem location of the JSON index file. The keyring is used for all secret storage and retrieval.

func (*SessionIndex) Delete

func (si *SessionIndex) Delete() error

Delete removes the session for (account, service) from both the keyring and the on-disk index. If the account or session doesn't exist, Delete returns nil (idempotent). If the account has no remaining sessions after deletion, the account entry is removed entirely.

func (*SessionIndex) List

func (si *SessionIndex) List() ([]string, error)

List returns the account names present in the session index file. A missing index file is treated as an empty list (no error).

func (*SessionIndex) Load

func (si *SessionIndex) Load() (*api.SessionCredentials, error)

Load resolves (account, service) to a UUID via the index file, then retrieves the SessionCredentials from the keyring. It tries the exact service first, then falls back to the "*" wildcard. Stale index entries (UUID present in index but missing from keyring) are cleaned up automatically.

func (*SessionIndex) Save

func (si *SessionIndex) Save(session *api.SessionCredentials) error

Save stores the given SessionCredentials in the keyring and updates the on-disk index file. If no entry exists for (account, service), a new v4 UUID is generated as the keyring key. Parent directories for the index file are created if they don't exist.

func (*SessionIndex) Switch

func (si *SessionIndex) Switch(account string) error

Switch updates the active account on this SessionIndex instance.

type SessionIndexData

type SessionIndexData struct {
	Accounts map[string]AccountEntry `json:"accounts"`
}

SessionIndexData is the on-disk JSON structure for the session index file.

type SystemKeyring

type SystemKeyring struct{}

SystemKeyring delegates to go-keyring's package-level functions.

func (SystemKeyring) Delete

func (SystemKeyring) Delete(service, account string) error

Delete removes a secret from the system keyring.

func (SystemKeyring) Get

func (SystemKeyring) Get(service, account string) (string, error)

Get retrieves a secret from the system keyring.

func (SystemKeyring) Set

func (SystemKeyring) Set(service, account, password string) error

Set stores a secret in the system keyring.

Directories

Path Synopsis
Package accountCmd implements the account subcommands for proton-cli.
Package accountCmd implements the account subcommands for proton-cli.
Package configCmd implements the proton config subcommand tree.
Package configCmd implements the proton config subcommand tree.
Package driveCmd implements the drive subcommands for proton-cli.
Package driveCmd implements the drive subcommands for proton-cli.
share
Package shareCmd implements the share subcommands for proton-cli.
Package shareCmd implements the share subcommands for proton-cli.
Package lumoCmd implements the lumo subcommands for proton-cli.
Package lumoCmd implements the lumo subcommands for proton-cli.

Jump to

Keyboard shortcuts

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