Documentation
¶
Overview ¶
Package cli implements the command-line interface for proton-cli.
Index ¶
- Constants
- func AddCommand(cmd *cobra.Command)
- func BoolFlag(fs *pflag.FlagSet, p *bool, name string, value bool, usage string)
- func BoolFlagP(fs *pflag.FlagSet, p *bool, name, shorthand string, value bool, usage string)
- func ConfigFilePath() string
- func Execute()
- func InstallDebugHooks(m *proton.Manager)
- func NewDriveClient(ctx context.Context, session *common.Session) (*drive.Client, error)
- func RegisterProfileFlag()
- func SetContext(cmd *cobra.Command, rc *RuntimeContext)
- func SetServiceCmd(cmd *cobra.Command, service string)
- func SetupSession(ctx context.Context, cmd *cobra.Command) (*common.Session, error)
- func StartProfile() func()
- func UserPrompt(prompt string, password bool) (string, error)
- type AccountEntry
- type Keyring
- type RuntimeContext
- type SessionIndex
- type SessionIndexData
- type SystemKeyring
Constants ¶
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 ¶
AddCommand registers a subcommand with the root command.
func BoolFlag ¶
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 ConfigFilePath ¶
func ConfigFilePath() string
ConfigFilePath returns the resolved config file path.
func InstallDebugHooks ¶
InstallDebugHooks adds pre-request and post-response logging hooks to the proton manager. Called when verbosity >= 3.
func NewDriveClient ¶
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 ¶
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 ¶
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.
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.
Source Files
¶
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. |