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
44 45 46 47 48 49 50 |
# File 'lib/kapusta/cli.rb', line 44 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
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kapusta/cli.rb', line 31 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
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kapusta/cli.rb', line 52 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 |
# 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 end |
.usage ⇒ Object
63 64 65 |
# File 'lib/kapusta/cli.rb', line 63 def self.usage 'usage: kapusta [--compile|-c] <file.kap> | kapusta <file.kap> [args...]' end |