Module: Twig::Subcommands
- Defined in:
- lib/twig/subcommands.rb
Constant Summary collapse
- BIN_PREFIX =
'twig-'
Class Method Summary collapse
Class Method Details
.all_names ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/twig/subcommands.rb', line 5 def self.all_names bin_paths = [] bin_dir_paths.each do |bin_dir_path| path_pattern = File.join(bin_dir_path, BIN_PREFIX + '*') Dir.glob(path_pattern) do |bin_path| bin_paths << File.basename(bin_path) end end bin_paths.uniq.sort.map do |bin_path| bin_path.sub(Regexp.new('^' << BIN_PREFIX), '') end end |
.bin_dir_paths ⇒ Object
20 21 22 |
# File 'lib/twig/subcommands.rb', line 20 def self.bin_dir_paths ENV['PATH'].split(':') end |
.exec_subcommand_if_any(cli_args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/twig/subcommands.rb', line 24 def self.exec_subcommand_if_any(cli_args) # Run subcommand binary, if any, and exit here subcommand_name = cli_args[0] bin_name = Twig::Subcommands::BIN_PREFIX + subcommand_name subcommand_path = Twig.run("which #{bin_name} 2>/dev/null") return if subcommand_path.empty? subcommand_args = cli_args[1..-1] command = ([subcommand_path] + subcommand_args).join(' ') exec(command) end |