Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DatabaseConfig ¶
type Deeply ¶
type Deeply struct {
Setting string `flag:"deep-setting" default:"default-deep-setting"`
Deeper EvenDeeper
}
type Environment ¶
type Environment string
const ( EnvDevelopment Environment = "dev" EnvStaging Environment = "staging" EnvProduction Environment = "prod" )
type EvenDeeper ¶
type LogsOptions ¶
type LogsOptions struct {
flagkit.Follow
flagkit.Output
flagkit.Timeout
flagkit.Quiet
Service string `flag:"service" flagshort:"s" flagdescr:"Service name to show logs for" flagrequired:"true"`
}
LogsOptions demonstrates flagkit composition with multiple types. Combines Follow, Output, Timeout, and Quiet with an app-specific Service flag.
type PresetDemoOptions ¶
type PresetDemoOptions struct {
Role string `flag:"role" flagpreset:"as-admin=admin;as-guest=guest;as-super=superadmin" validate:"required,oneof=admin guest"`
Label string `flag:"label" flagpreset:"auto-label= john doe " mod:"trim,title" validate:"required,min=3,max=32"`
}
PresetDemoOptions demonstrates flagpreset values flowing through transform and validation logic.
type ServerOptions ¶
type ServerOptions struct {
// Basic flags
Host string `flag:"host" flagdescr:"Server host" default:"localhost"`
Port int `flagshort:"p" flagdescr:"Server port" flagrequired:"true" flagenv:"true"`
// Environment variable binding
APIKey string `flagenv:"true" flagdescr:"API authentication key"`
// Env-only field: settable only via environment variable, not CLI flag
SecretKey string `flagenv:"only" flag:"secret-key" flagdescr:"Secret signing key (env only)"`
// Same in-memory type (bytes), different textual contracts at the CLI boundary.
TokenHex structcli.Hex `flag:"token-hex" flaggroup:"Security" flagdescr:"Token bytes encoded as hex" flagenv:"true" default:"68656c6c6f"`
TokenBase64 structcli.Base64 `flag:"token-base64" flaggroup:"Security" flagdescr:"Token bytes encoded as base64" flagenv:"true" default:"aGVsbG8="`
// Network contracts using net families.
BindIP net.IP `flag:"bind-ip" flaggroup:"Network" flagdescr:"Bind interface IP" flagenv:"true" default:"127.0.0.1"`
BindMask net.IPMask `flag:"bind-mask" flaggroup:"Network" flagdescr:"Bind interface mask" flagenv:"true" default:"ffffff00"`
AdvertiseCIDR net.IPNet `flag:"advertise-cidr" flaggroup:"Network" flagdescr:"Advertised service subnet (CIDR)" flagenv:"true" default:"127.0.0.0/24"`
TrustedPeers []net.IP `` /* 132-byte string literal not displayed */
// Flag grouping for organized help
LogLevel zapcore.Level `flag:"log-level" flaggroup:"Logging" flagdescr:"Set log level"`
LogFile string `flag:"log-file" flaggroup:"Logging" flagdescr:"Log file path" flagenv:"true"`
// Nested structs for organization
Database DatabaseConfig `flaggroup:"Database"`
// Custom type
TargetEnv Environment `flag:"target-env" flagdescr:"Set the target environment" default:"dev"`
Deep Deeply
}
type UserConfig ¶
type UserConfig struct {
Email string `flag:"email" flagdescr:"User email" validate:"email"`
Age int `flag:"age" flagdescr:"User age" validate:"min=18,max=120"`
Name string `flag:"name" flagdescr:"User name" mod:"trim,title"`
}
type UtilityFlags ¶
type UtilityFlags struct {
Verbose int `flagtype:"count" flagshort:"v" flaggroup:"Utility"`
DryRun bool `flag:"dry" flaggroup:"Utility" flagenv:"true"`
}
func (*UtilityFlags) Context ¶
func (f *UtilityFlags) Context(ctx context.Context) context.Context
Context propagates UtilityFlags into the command context during unmarshal.
func (*UtilityFlags) FromContext ¶
func (f *UtilityFlags) FromContext(ctx context.Context) error
Click to show internal directories.
Click to hide internal directories.