Class: Halation::Script
- Inherits:
-
Object
- Object
- Halation::Script
- Defined in:
- lib/halation/script.rb
Overview
The script that runs when the halation binary is executed.
Class Method Summary collapse
-
.generate_new_roll(opts = {}) ⇒ Object
Generate a new roll.yml file.
- .run(opts = {}) ⇒ Object
Class Method Details
.generate_new_roll(opts = {}) ⇒ Object
Generate a new roll.yml file. Copies “~/.halation/templates/roll.yml” if it exists, otherwise it uses a default template.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/halation/script.rb', line 89 def self.generate_new_roll(opts = {}) skip_exit = !!opts[:skip_exit] roll_path = "roll.yml" if File.exists?(roll_path) STDERR.puts "A roll.yml file already exists in this directory." exit 1 unless skip_exit end # TODO: Make this configurable from config.yml roll_template_path = File.("~/.halation/templates/roll.yml") if File.exists?(roll_template_path) FileUtils.cp(roll_template_path, ".") else File.open(roll_path, "w") do |f| f.puts new_roll_content end end end |
.run(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/halation/script.rb', line 16 def self.run(opts = {}) args = opts[:args] || ARGV output_stream = opts[:output_stream] || STDOUT skip_exit = !!opts[:skip_exit] run_engine = true = {} OptionParser.new { |op| op. = "Usage: halation [options]" op.on("-c", "--config=PATH", String, "Config file path") do |config_path| [:config_path] = config_path end op.on("--dry", "Dry run") do [:dry_run] = true # TODO: Implement raise NotImplementedError, "Dry run option is not yet implemented." end op.on("-h", "--help", "Print this help") do output_stream.puts op run_engine = false exit unless skip_exit end op.on("--new-config", "Generate a new config file") do |path| # TODO: Implement raise NotImplementedError, "Generate config option is not yet implemented." run_engine = false exit unless skip_exit end op.on("--new-roll", "Generate a new roll.yml file") do generate_new_roll(opts) run_engine = false exit unless skip_exit end op.on("-p", "--print-config", "Print the configuration settings") do # TODO: Implement raise NotImplementedError, "Print config option is not yet implemented." run_engine = false exit unless skip_exit end op.on("-r", "--recursive", "Traverse into subdirectories") do # TODO: Implement raise NotImplementedError, "Recursive option is not yet implemented." end op.on("--silent", "Suppress messages to stdout.") do [:silent] = true end op.on("-v", "--version", "Print the version information") do output_stream.puts "halation #{Halation::VERSION}" run_engine = false exit unless skip_exit end }.parse!(args) Halation::Engine.run() if run_engine end |