class Dothtml::CLI
Constants
- COMMANDS
- COMMAND_NAMES
- DEFAULT_COMMAND
- VERSION_STRING
Attributes
args[R]
command[RW]
Public Class Methods
new(args)
click to toggle source
# File lib/dothtml/cli.rb, line 37 def initialize(args) @args = args end
Public Instance Methods
execute()
click to toggle source
# File lib/dothtml/cli.rb, line 41 def execute parse_global_options parse_command_options execute_command end
Private Instance Methods
build_command()
click to toggle source
# File lib/dothtml/cli.rb, line 93 def build_command files = if args.empty? Dir.glob("*.dot").sort else args.select { |a| a.end_with?(".dot") } end DotTask.new.build(files) end
create_command()
click to toggle source
# File lib/dothtml/cli.rb, line 104 def create_command dir = args.shift Trollop.die "dir not specified" if dir.nil? DotTask.new.create(dir) end
execute_command()
click to toggle source
Command handlers
# File lib/dothtml/cli.rb, line 89 def execute_command send("#{command}_command") end
help_command()
click to toggle source
# File lib/dothtml/cli.rb, line 125 def help_command Trollop.educate end
indent(string, amount)
click to toggle source
# File lib/dothtml/cli.rb, line 80 def indent(string, amount) prefix = " " * amount string.lines.map { |l| "#{prefix}#{l}" }.join end
parse_command_options()
click to toggle source
# File lib/dothtml/cli.rb, line 65 def parse_command_options self.command = (args.shift || DEFAULT_COMMAND).downcase Trollop.die "invalid command, '#{command}'" unless COMMAND_NAMES.include?(command) return unless COMMANDS.key?(command) command_options = COMMANDS[command] command_synopsis = "\n#{indent(command_options["synopsis"], 1)}".chomp Trollop.options(args) do version VERSION_STRING usage command_options["usage"] synopsis command_synopsis end end
parse_global_options()
click to toggle source
# File lib/dothtml/cli.rb, line 51 def parse_global_options global_synopsis_parts = COMMANDS.each_value.flat_map do |v| [indent(v["usage"], 1), indent(v["synopsis"], 2)] end global_synopsis = "\nCommands:\n#{global_synopsis_parts.join("\n")}".chomp Trollop.options(args) do version VERSION_STRING usage "<command> [command_options]" synopsis global_synopsis stop_on COMMAND_NAMES end end
version_command()
click to toggle source
# File lib/dothtml/cli.rb, line 120 def version_command puts VERSION_STRING exit 0 end
watch_command()
click to toggle source
# File lib/dothtml/cli.rb, line 111 def watch_command guardfile = File.join(TEMPLATES_DIR, "Guardfile") env = { "DOTHTML_PATH" => File.expand_path($0), "BUNDLE_GEMFILE" => File.expand_path("../../Gemfile", __dir__) } exec(env, "bundle exec guard -G #{guardfile}") end