Module: CdExec
- Defined in:
- lib/cdexec.rb
Class Method Summary collapse
-
.cli(*argv) ⇒ Object
Command line interface.
-
.command_line(*args) ⇒ Object
Glue the command line together, adding double quotes if argument contains spaces.
-
.display_help ⇒ Object
Display help message and exit.
-
.man_file ⇒ Object
Path to roff man-page file.
-
.ronn_file ⇒ Object
Path to ronn man-page file.
Class Method Details
.cli(*argv) ⇒ Object
Command line interface.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cdexec.rb', line 6 def self.cli(*argv) case i = argv.index('-') when nil dirs, args = argv, Dir['*'] else dirs, args = argv[0...i], argv[i+1..-1] end help = dirs.delete('-h') || dirs.delete('--help') trace = dirs.delete('-t') || dirs.delete('--trace') display_help if help dirs = dirs.select{ |dir| File.directory?(dir) } dirs.each_with_index do |dir, idx| puts "\n#{idx+1}. #{dir}" if trace Dir.chdir dir do system command_line(*args) end end end |
.command_line(*args) ⇒ Object
Glue the command line together, adding double quotes if argument contains spaces.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cdexec.rb', line 31 def self.command_line(*args) args.map do |a| case a when /\s/ %{"#{a}"} else a end end.join(' ') end |
.display_help ⇒ Object
Display help message and exit.
43 44 45 46 |
# File 'lib/cdexec.rb', line 43 def self.display_help system "man #{man_file}" || puts(File.read(ronn_file)) exit 0 end |
.man_file ⇒ Object
Path to roff man-page file.
49 50 51 |
# File 'lib/cdexec.rb', line 49 def self.man_file File.dirname(__FILE__) + '/../man/cdexe.1' end |
.ronn_file ⇒ Object
Path to ronn man-page file.
54 55 56 |
# File 'lib/cdexec.rb', line 54 def self.ronn_file File.dirname(__FILE__) + '/../man/cdexe.1.ronn' end |