cli #

Usage example:

module main

import os
import cli

fn main() {
    mut app := cli.Command{
        name: 'example-app'
        description: 'example-app'
        execute: fn (cmd cli.Command) ? {
            println('hello app')
            return
        }
        commands: [
            cli.Command{
                name: 'sub'
                execute: fn (cmd cli.Command) ? {
                   println('hello subcommand')
                   return
                }
            },
        ]
    }
    app.setup()
    app.parse(os.args)
}

fn ([]Flag) get_all_found #

fn (flags []Flag) get_all_found() []Flag

fn ([]Flag) get_bool #

fn (flags []Flag) get_bool(name string) ?bool

fn ([]Flag) get_int #

fn (flags []Flag) get_int(name string) ?int

fn ([]Flag) get_float #

fn (flags []Flag) get_float(name string) ?f64

fn ([]Flag) get_string #

fn (flags []Flag) get_string(name string) ?string

fn (FnCommandCallback) str #

fn (f FnCommandCallback) str() string

enum FlagType #

enum FlagType {
	bool
	int
	float
	string
}

struct Command #

struct Command {
pub mut:
	name            string
	usage           string
	description     string
	version         string
	pre_execute     FnCommandCallback
	execute         FnCommandCallback
	post_execute    FnCommandCallback
	disable_help    bool
	disable_version bool
	disable_flags   bool
	sort_flags      bool     = true
	sort_commands   bool     = true
	parent          &Command = 0
	commands        []Command
	flags           []Flag
	required_args   int
	args            []string
}

fn (Command) str #

fn (cmd Command) str() string

fn (Command) is_root #

fn (cmd Command) is_root() bool

fn (Command) root #

fn (cmd Command) root() Command

fn (Command) full_name #

fn (cmd Command) full_name() string

fn (Command) add_commands #

fn (mut cmd Command) add_commands(commands []Command)

fn (Command) add_command #

fn (mut cmd Command) add_command(command Command)

fn (Command) setup #

fn (mut cmd Command) setup()

fn (Command) add_flags #

fn (mut cmd Command) add_flags(flags []Flag)

fn (Command) add_flag #

fn (mut cmd Command) add_flag(flag Flag)

fn (Command) parse #

fn (mut cmd Command) parse(args []string)

fn (Command) execute_help #

fn (cmd Command) execute_help()

struct Flag #

struct Flag {
pub mut:
	flag        FlagType
	name        string
	abbrev      string
	description string
	global      bool
	required    bool
	value       string
mut:
	found bool
}

fn (Flag) get_bool #

fn (flag Flag) get_bool() ?bool

fn (Flag) get_int #

fn (flag Flag) get_int() ?int

fn (Flag) get_float #

fn (flag Flag) get_float() ?f64

fn (Flag) get_string #

fn (flag Flag) get_string() ?string