Documentation
¶
Index ¶
- func ApplyCommand() *C.Command
- func BindCommand() *C.Command
- func BoolFlagPrism() P.Prism[C.Flag, *C.BoolFlag]
- func Commands() []*C.Command
- func ContextReaderIOEitherCommand() *C.Command
- func DICommand() *C.Command
- func DurationFlagPrism() P.Prism[C.Flag, *C.DurationFlag]
- func EitherCommand() *C.Command
- func Float64FlagPrism() P.Prism[C.Flag, *C.Float64Flag]
- func Float64SliceFlagPrism() P.Prism[C.Flag, *C.Float64SliceFlag]
- func IOCommand() *C.Command
- func IOEitherCommand() *C.Command
- func IOOptionCommand() *C.Command
- func IdentityCommand() *C.Command
- func Int64FlagPrism() P.Prism[C.Flag, *C.Int64Flag]
- func IntFlagPrism() P.Prism[C.Flag, *C.IntFlag]
- func IntSliceFlagPrism() P.Prism[C.Flag, *C.IntSliceFlag]
- func LensCommand() *C.Command
- func MakeCommand(name string, usage string, flags []C.Flag, effect CommandEffect) *C.Command
- func MakeCommandWithSubcommands(name string, usage string, flags []C.Flag, commands []*C.Command, ...) *C.Command
- func OptionCommand() *C.Command
- func PipeCommand() *C.Command
- func ReaderCommand() *C.Command
- func ReaderIOEitherCommand() *C.Command
- func StringFlagPrism() P.Prism[C.Flag, *C.StringFlag]
- func StringSliceFlagPrism() P.Prism[C.Flag, *C.StringSliceFlag]
- func TimestampFlagPrism() P.Prism[C.Flag, *C.TimestampFlag]
- func ToAction(effect CommandEffect) func(context.Context, *C.Command) error
- func TupleCommand() *C.Command
- func Uint64FlagPrism() P.Prism[C.Flag, *C.Uint64Flag]
- func UintFlagPrism() P.Prism[C.Flag, *C.UintFlag]
- type CommandEffect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCommand ¶
func BindCommand ¶
func BoolFlagPrism ¶ added in v2.2.20
BoolFlagPrism creates a Prism for extracting a BoolFlag from a Flag. This provides a type-safe way to work with boolean flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.BoolFlag] for safe BoolFlag extraction
Example Usage ¶
prism := BoolFlagPrism()
// Extract BoolFlag from Flag
var flag C.Flag = &C.BoolFlag{Name: "verbose", Value: true}
result := prism.GetOption(flag) // Some(*C.BoolFlag{...})
func DurationFlagPrism ¶ added in v2.2.20
DurationFlagPrism creates a Prism for extracting a DurationFlag from a Flag. This provides a type-safe way to work with duration flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.DurationFlag] for safe DurationFlag extraction
Example Usage ¶
prism := DurationFlagPrism()
// Extract DurationFlag from Flag
var flag C.Flag = &C.DurationFlag{Name: "timeout", Value: 30 * time.Second}
result := prism.GetOption(flag) // Some(*C.DurationFlag{...})
func EitherCommand ¶
func Float64FlagPrism ¶ added in v2.2.20
Float64FlagPrism creates a Prism for extracting a Float64Flag from a Flag. This provides a type-safe way to work with float64 flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.Float64Flag] for safe Float64Flag extraction
Example Usage ¶
prism := Float64FlagPrism()
// Extract Float64Flag from Flag
var flag C.Flag = &C.Float64Flag{Name: "ratio", Value: 0.5}
result := prism.GetOption(flag) // Some(*C.Float64Flag{...})
func Float64SliceFlagPrism ¶ added in v2.2.20
Float64SliceFlagPrism creates a Prism for extracting a Float64SliceFlag from a Flag. This provides a type-safe way to work with float64 slice flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.Float64SliceFlag] for safe Float64SliceFlag extraction
Example Usage ¶
prism := Float64SliceFlagPrism()
// Extract Float64SliceFlag from Flag
var flag C.Flag = &C.Float64SliceFlag{Name: "ratios"}
result := prism.GetOption(flag) // Some(*C.Float64SliceFlag{...})
func IOEitherCommand ¶
func IOOptionCommand ¶
func IdentityCommand ¶
func Int64FlagPrism ¶ added in v2.2.20
Int64FlagPrism creates a Prism for extracting an Int64Flag from a Flag. This provides a type-safe way to work with int64 flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.Int64Flag] for safe Int64Flag extraction
Example Usage ¶
prism := Int64FlagPrism()
// Extract Int64Flag from Flag
var flag C.Flag = &C.Int64Flag{Name: "offset"}
result := prism.GetOption(flag) // Some(*C.Int64Flag{...})
func IntFlagPrism ¶ added in v2.2.20
IntFlagPrism creates a Prism for extracting an IntFlag from a Flag. This provides a type-safe way to work with integer flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.IntFlag] for safe IntFlag extraction
Example Usage ¶
prism := IntFlagPrism()
// Extract IntFlag from Flag
var flag C.Flag = &C.IntFlag{Name: "count", Value: 10}
result := prism.GetOption(flag) // Some(*C.IntFlag{...})
func IntSliceFlagPrism ¶ added in v2.2.20
IntSliceFlagPrism creates a Prism for extracting an IntSliceFlag from a Flag. This provides a type-safe way to work with int slice flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.IntSliceFlag] for safe IntSliceFlag extraction
Example Usage ¶
prism := IntSliceFlagPrism()
// Extract IntSliceFlag from Flag
var flag C.Flag = &C.IntSliceFlag{Name: "ports"}
result := prism.GetOption(flag) // Some(*C.IntSliceFlag{...})
func LensCommand ¶
LensCommand creates the CLI command for lens generation
func MakeCommand ¶ added in v2.2.20
MakeCommand creates a new Command with an Effect-based action. This is a convenience function that combines command creation with Effect conversion.
Parameters ¶
- name: The command name
- usage: The command usage description
- flags: The command flags
- effect: The CommandEffect to use as the action
Returns ¶
- A *C.Command configured with the Effect-based action
Example Usage ¶
cmd := MakeCommand(
"process",
"Process data files",
[]C.Flag{
&C.StringFlag{Name: "input", Usage: "Input file"},
},
func(cmd *C.Command) E.Thunk[F.Void] {
return func(ctx context.Context) E.IOResult[F.Void] {
return func() R.Result[F.Void] {
input := cmd.String("input")
// Process input...
return R.Of(F.Void{})
}
}
},
)
func MakeCommandWithSubcommands ¶ added in v2.2.20
func MakeCommandWithSubcommands( name string, usage string, flags []C.Flag, commands []*C.Command, effect CommandEffect, ) *C.Command
MakeCommandWithSubcommands creates a new Command with subcommands and an Effect-based action.
Parameters ¶
- name: The command name
- usage: The command usage description
- flags: The command flags
- commands: The subcommands
- effect: The CommandEffect to use as the action
Returns ¶
- A *C.Command configured with subcommands and the Effect-based action
Example Usage ¶
cmd := MakeCommandWithSubcommands(
"app",
"Application commands",
[]C.Flag{},
[]*C.Command{subCmd1, subCmd2},
defaultEffect,
)
func OptionCommand ¶
func PipeCommand ¶
func ReaderCommand ¶
func ReaderIOEitherCommand ¶
func StringFlagPrism ¶ added in v2.2.20
StringFlagPrism creates a Prism for extracting a StringFlag from a Flag. This provides a type-safe way to work with string flags, handling type mismatches gracefully through the Option type.
The prism's GetOption attempts to cast a Flag to *C.StringFlag. If the cast succeeds, it returns Some(*C.StringFlag); if it fails, it returns None.
The prism's ReverseGet converts a *C.StringFlag back to a Flag.
Returns ¶
- A Prism[C.Flag, *C.StringFlag] for safe StringFlag extraction
Example Usage ¶
prism := StringFlagPrism()
// Extract StringFlag from Flag
var flag C.Flag = &C.StringFlag{Name: "input", Value: "default"}
result := prism.GetOption(flag) // Some(*C.StringFlag{...})
// Type mismatch returns None
var intFlag C.Flag = &C.IntFlag{Name: "count"}
result = prism.GetOption(intFlag) // None[*C.StringFlag]()
// Convert back to Flag
strFlag := &C.StringFlag{Name: "output"}
flag = prism.ReverseGet(strFlag)
func StringSliceFlagPrism ¶ added in v2.2.20
StringSliceFlagPrism creates a Prism for extracting a StringSliceFlag from a Flag. This provides a type-safe way to work with string slice flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.StringSliceFlag] for safe StringSliceFlag extraction
Example Usage ¶
prism := StringSliceFlagPrism()
// Extract StringSliceFlag from Flag
var flag C.Flag = &C.StringSliceFlag{Name: "tags"}
result := prism.GetOption(flag) // Some(*C.StringSliceFlag{...})
func TimestampFlagPrism ¶ added in v2.2.20
TimestampFlagPrism creates a Prism for extracting a TimestampFlag from a Flag. This provides a type-safe way to work with timestamp flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.TimestampFlag] for safe TimestampFlag extraction
Example Usage ¶
prism := TimestampFlagPrism()
// Extract TimestampFlag from Flag
var flag C.Flag = &C.TimestampFlag{Name: "created"}
result := prism.GetOption(flag) // Some(*C.TimestampFlag{...})
func ToAction ¶ added in v2.2.20
ToAction converts a CommandEffect into a standard urfave/cli Action function. This allows Effect-based command handlers to be used with the cli/v3 framework.
The conversion process:
- Takes the Effect which expects a *C.Command context
- Executes it with the provided command
- Runs the resulting IO operation
- Converts the Result to either nil (success) or error (failure)
Parameters ¶
- effect: The CommandEffect to convert
Returns ¶
- A function compatible with C.Command.Action signature
Example Usage ¶
effect := func(cmd *C.Command) E.Thunk[F.Void] {
return func(ctx context.Context) E.IOResult[F.Void] {
return func() R.Result[F.Void] {
// Command logic here
return R.Of(F.Void{})
}
}
}
action := ToAction(effect)
command := &C.Command{
Name: "example",
Action: action,
}
func TupleCommand ¶
func Uint64FlagPrism ¶ added in v2.2.20
Uint64FlagPrism creates a Prism for extracting a Uint64Flag from a Flag. This provides a type-safe way to work with uint64 flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.Uint64Flag] for safe Uint64Flag extraction
Example Usage ¶
prism := Uint64FlagPrism()
// Extract Uint64Flag from Flag
var flag C.Flag = &C.Uint64Flag{Name: "size"}
result := prism.GetOption(flag) // Some(*C.Uint64Flag{...})
func UintFlagPrism ¶ added in v2.2.20
UintFlagPrism creates a Prism for extracting a UintFlag from a Flag. This provides a type-safe way to work with unsigned integer flags, handling type mismatches gracefully through the Option type.
Returns ¶
- A Prism[C.Flag, *C.UintFlag] for safe UintFlag extraction
Example Usage ¶
prism := UintFlagPrism()
// Extract UintFlag from Flag
var flag C.Flag = &C.UintFlag{Name: "workers", Value: 4}
result := prism.GetOption(flag) // Some(*C.UintFlag{...})
Types ¶
type CommandEffect ¶ added in v2.2.20
CommandEffect represents a CLI command action as an Effect. The Effect takes a *C.Command as context and produces a result.
func FromAction ¶ added in v2.2.20
FromAction converts a standard urfave/cli Action function into a CommandEffect. This allows existing cli/v3 action handlers to be lifted into the Effect type.
The conversion process:
- Takes a standard action function (context.Context, *C.Command) -> error
- Wraps it in the Effect structure
- Converts the error result to a Result type
Parameters ¶
- action: The standard cli/v3 action function to convert
Returns ¶
- A CommandEffect that wraps the original action
Example Usage ¶
standardAction := func(ctx context.Context, cmd *C.Command) error {
// Existing command logic
return nil
}
effect := FromAction(standardAction)
// Now can be composed with other Effects