module Cli

Defined in:

cli.cr

Constant Summary

VERSION = {{ (`shards version /srv/crystaldoc.info/github-ralsina-markterm-v0.13.0/src`).chomp.stringify }}

Class Method Summary

Class Method Detail

def self.config_argv(app_name : String, argv : Array(String)) : Tuple(Array(String), String) #

Handle the --config option: pull it out of argv (both the "--config path" and "--config=path" forms; tokens after "--" are positional and never options) and return the stripped argv plus the config file path to use: the one given, or the tool's XDG default. An explicitly given file must exist; a --config with no value is left in argv so docopt reports the missing argument.


[View source]
def self.config_path(app_name : String) : String #

Default config file path for a tool, e.g. ~/.config/markterm/config.yml (or $XDG_CONFIG_HOME/markterm/config.yml)


[View source]
def self.option_flag(value : Docopt::OptionValue | Nil) : Bool #

Interpret an option as a boolean flag: true when the flag was given on the command line or set to true in the config file or environment (docopt-config coerces env var values), false or nil otherwise.


[View source]
def self.option_list(value : Docopt::OptionValue | Nil) : Array(String) #

docopt returns a String when a repeatable option occurs once, and an Array(String) when it repeats (on the command line or through a list in the config file); normalize to an Array(String) either way.


[View source]
def self.option_string(value : Docopt::OptionValue | Nil, fallback : String) : String #

Same, for options that carry a docopt [default: ...] and must not end up nil: fall back to the documented default.


[View source]
def self.option_string(value : Docopt::OptionValue | Nil) : String | Nil #

docopt-config returns config file values with their YAML types, so an option documented as taking a string can come back as a number (e.g. "margin: 20" as Int32, "margin: 20.5" as Float64, or a numeric docopt default). Normalize those to the String docopt would have produced, ignoring values of other types.


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

Read the input file, or standard input when the file is "-"


[View source]