Module: Slidict::Cli::Options

Included in:
App, Lint, Serve, Slides
Defined in:
lib/slidict/cli/options.rb

Overview

Concern for CLI classes with several constructor dependencies. Declaring options name: -> { default }, ... once generates both the attr_reader and the initialize assignment, instead of repeating each dependency in the method signature and again as @name = name in the body.

Defaults are instance_exec'd lazily (only when the keyword is omitted), matching plain keyword-argument defaults, and may reference other options or instance methods (e.g. -> { method(:default_linter) }). Classes that need to post-process a value (e.g. expanding a path) can still override initialize, call super, and adjust the ivar.

Also provides a flag/parse_flags!/flags_help DSL: declaring a -x/--xxx switch once (with its arg placeholder and description) drives both argv parsing and the --help listing, so the two can't drift apart. usage then only needs to hold the surrounding usage text (Usage:/Commands: lines), interpolating flags_help for the option list.

Defined Under Namespace

Modules: ClassMethods Classes: Flag

Constant Summary collapse

MISSING =
Object.new.freeze
SUCCESS =

Process exit codes (see bin/slidict, which does exit App.new.run(ARGV)), named so command methods don't scatter bare 0/1 literals as return values.

0
FAILURE =
1

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



29
30
31
# File 'lib/slidict/cli/options.rb', line 29

def self.included(base)
  base.extend(ClassMethods)
end