Module: Work::Md::Cli
- Defined in:
- lib/work/md/cli.rb
Defined Under Namespace
Classes: CommandMissing
Constant Summary collapse
- ALIAS_COMMANDS =
{ 't' => 'today', 'ty' => 'tyesterday', 'y' => 'yesterday', 'to' => 'tomorrow', 'c' => 'config', 'p' => 'parse', 'pl' => 'plast', 'a' => 'annotations', 'o' => 'open', 'd' => 'delete', 'l' => 'last', 'tl' => 'tlast' }.freeze
Class Method Summary collapse
- .error_frame_style ⇒ Object
- .execute(argv, development: false) ⇒ Object
- .fetch_argv_keys(argv) ⇒ Object
- .help(message = '') ⇒ Object
- .normal_frame_style ⇒ Object
Class Method Details
.error_frame_style ⇒ Object
90 91 92 93 94 95 |
# File 'lib/work/md/cli.rb', line 90 def self.error_frame_style { padding: 1, title: { top_left: '(error)' } } end |
.execute(argv, development: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/work/md/cli.rb', line 24 def self.execute(argv, development: false) first_argv_argument = argv.shift tag = fetch_argv_keys(argv)['tag'] if tag ENV['WORK_MD_TAG'] = tag argv.reject! { |arg| arg.include?('-tag=') } end ::FileUtils.mkdir_p(Work::Md::Config.work_dir) raise CommandMissing if first_argv_argument.nil? command = (ALIAS_COMMANDS[first_argv_argument] || first_argv_argument).capitalize Object .const_get("Work::Md::Commands::#{command}") .send(:execute, argv) rescue NameError puts help( ::TTY::Box.frame( "Command '#{first_argv_argument}' not found!", **error_frame_style ) ) rescue CommandMissing help('Welcome! =)') end |
.fetch_argv_keys(argv) ⇒ Object
97 98 99 |
# File 'lib/work/md/cli.rb', line 97 def self.fetch_argv_keys(argv) Hash[argv.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)] end |
.help(message = '') ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/work/md/cli.rb', line 55 def self.help( = '') # rubocop:disable Layout/LineLength puts ::TTY::Box.frame( , 'Track your work activities, write annotations, recap what you did for a week, month or specific days... and much more!', '', 'commands available:', '', '- work-md', '- work-md today', '- work-md yesterday', '- work-md tyesterday', '- work-md tomorrow', '- work-md last', '- work-md tlast', '- work-md parse', '- work-md plast', '- work-md annotations', '- work-md daily', '- work-md open', '- work-md config', '', 'for more information: github.com/work-md', **normal_frame_style ) # rubocop:enable Layout/LineLength end |