class Jargon::CLI

Defined in:

jargon/cli.cr
jargon/config.cr
jargon/help.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from_file(path : String, program_name : String = "cli") : CLI #

Create a CLI from a JSON schema file


[View source]
def self.from_json(json : String, program_name : String = "cli") : CLI #

Create a CLI from a JSON schema string


[View source]
def self.from_yaml(yaml : String, program_name : String = "cli") : CLI #

Create a CLI from a YAML schema string


[View source]
def self.new(schema : Schema, program_name : String = "cli") #

[View source]
def self.new(program_name : String) #

[View source]

Instance Method Detail

def bash_completion : String #

[View source]
def config_paths : Array(String) #

Returns the list of config paths that would be searched


[View source]
def default_subcommand(name : String) #

[View source]
def default_subcommand : String | Nil #

[View source]
def fish_completion : String #

[View source]
def help(subcommand : String) : String #

[View source]
def help : String #

[View source]
def load_config(*, merge : Bool = true) : JSON::Any | Nil #

Load config from standard locations. Supports YAML (.yaml, .yml) and JSON (.json) files.

Paths searched (in order):

  1. ./.config/{program_name}.yaml/.yml/.json (project local, flat)
  2. ./.config/{program_name}/config.yaml/.yml/.json (project local, directory)
  3. $XDG_CONFIG_HOME/{program_name}.yaml/.yml/.json (user global, flat)
  4. $XDG_CONFIG_HOME/{program_name}/config.yaml/.yml/.json (user global, directory)

With merge: true (default), merges all configs found (project wins over user). With merge: false, returns first config found. Returns nil if no config file found.


[View source]
def parse(args : Array(String), input : IO, *, defaults : JSON::Any | Hash(String, JSON::Any) | Nil = nil) : Result #

[View source]
def parse(args : Array(String), *, defaults : JSON::Any | Hash(String, JSON::Any) | Nil = nil) : Result #

[View source]
def program_name : String #

[View source]
def schema : Schema | Nil #

[View source]
def subcommand(name : String, schema : Schema | String) #

[View source]
def subcommand(name : String, cli : CLI) #

[View source]
def subcommand_key(key : String) #

[View source]
def subcommand_key : String #

[View source]
def subcommands : Hash(String, Schema | CLI) #

[View source]
def validate(data : Hash(String, JSON::Any), subcommand : String | Nil = nil) : Array(String) #

Validate data against a schema, returning any errors. If no schema is provided, uses the CLI's root schema. For subcommand validation, pass the subcommand name (space-separated for nested).


[View source]
def validate(result : Result) : Array(String) #

[View source]
def zsh_completion : String #

[View source]