Class: Kapusta::CLI
- Inherits:
-
Object
- Object
- Kapusta::CLI
- Defined in:
- lib/kapusta/cli.rb
Defined Under Namespace
Classes: Options
Class Method Summary collapse
- .compile_file(args) ⇒ Object
- .parse_options(args) ⇒ Object
- .run_file(args) ⇒ Object
- .start(argv = ARGV) ⇒ Object
- .usage ⇒ Object
Class Method Details
.compile_file(args) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/kapusta/cli.rb', line 47 def self.compile_file(args) path = args.shift abort usage unless path abort usage unless args.empty? $stdout.write(Kapusta.compile(File.read(path), path:)) end |
.parse_options(args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kapusta/cli.rb', line 34 def self.(args) = Options.new(compile: false, help: false, version: false) OptionParser.new do |parser| parser. = usage parser.on('-c', '--compile', 'Compile .kap to Ruby') { .compile = true } parser.on('-h', '--help', 'Show this help') { .help = true } parser.on('-v', '--version', 'Show version') { .version = true } end.order!(args) end |
.run_file(args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kapusta/cli.rb', line 55 def self.run_file(args) path = args.shift abort usage unless path previous_argv = ARGV.dup ARGV.replace(args) Kapusta.dofile(path) ensure ARGV.replace(previous_argv) if previous_argv end |
.start(argv = ARGV) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kapusta/cli.rb', line 10 def self.start(argv = ARGV) args = argv.dup = (args) if .help $stdout.puts usage return end if .version $stdout.puts "kapusta #{Kapusta::VERSION}" return end if .compile compile_file(args) else run_file(args) end rescue Kapusta::Error => e warn e.formatted exit 1 end |
.usage ⇒ Object
66 67 68 |
# File 'lib/kapusta/cli.rb', line 66 def self.usage 'usage: kapusta [--compile|-c] <file.kap> | kapusta <file.kap> [args...]' end |