Module: Resme::CommandSemantics
- Defined in:
- lib/resme/cli/command_semantics.rb
Constant Summary collapse
Class Method Summary collapse
-
.check(opts, argv) ⇒ Object
APP SPECIFIC COMMANDS.
- .console(opts, argv = []) ⇒ Object
- .europass(opts, argv) ⇒ Object
- .help(opts = nil, argv = []) ⇒ Object
- .init(opts, argv) ⇒ Object
- .json(opts, argv) ⇒ Object
- .man(opts = nil, argv = []) ⇒ Object
- .md(opts, argv) ⇒ Object
- .org(opts, argv) ⇒ Object
-
.reps(all_commands, argv) ⇒ Object
read-eval-print step.
-
.version(opts = nil, argv = []) ⇒ Object
Main App Starts Here!.
Class Method Details
.check(opts, argv) ⇒ Object
APP SPECIFIC COMMANDS
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/resme/cli/command_semantics.rb', line 95 def self.check opts, argv schema = Kwalify::Yaml.load_file(File.join(File.dirname(__FILE__), "/../templates/schema.yml")) ## or # schema = YAML.load_file('schema.yaml') ## create validator validator = Kwalify::Validator.new(schema) ## load document document = Kwalify::Yaml.load_file(argv[0]) ## or #document = YAML.load_file('document.yaml') ## validate errors = validator.validate(document) ## show errors if errors && !errors.empty? for e in errors puts "[#{e.path}] #{e.}" end else puts "The file #{argv[0]} validates." end end |
.console(opts, argv = []) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/resme/cli/command_semantics.rb', line 45 def self.console opts, argv = [] all_commands = CommandSyntax.commands all_commands.delete(:console) i = 0 while true string = Readline.readline("#{APPNAME}:%03d> " % i, true) string.gsub!(/^#{APPNAME} /, "") # as a courtesy, remove any leading appname string if string == "exit" or string == "quit" or string == "." then exit 0 end reps all_commands, string.split(' ') i = i + 1 end end |
.europass(opts, argv) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/resme/cli/command_semantics.rb', line 160 def self.europass opts, argv output = opts[:output] || "resume-#{Date.today}.xml" template = File.join(File.dirname(__FILE__), "/../templates/europass/eu.xml.erb") render argv, template, output puts "Resume generated in #{output}" puts "Render via, e.g., http://interop.europass.cedefop.europa.eu/web-services/remote-upload/" end |
.help(opts = nil, argv = []) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/resme/cli/command_semantics.rb', line 29 def self.help opts = nil, argv = [] all_commands = CommandSyntax.commands if argv != [] argv.map { |x| puts all_commands[x.to_sym][2] } else puts "#{APPNAME} command [options] [args]" puts "" puts "Available commands:" puts "" all_commands.keys.each do |key| puts " " + all_commands[key][0]. end end end |
.init(opts, argv) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/resme/cli/command_semantics.rb', line 121 def self.init opts, argv output = opts[:output] || "resume.yml" force = opts[:force] template = File.join(File.dirname(__FILE__), "/../templates/resume.yml") # avoid catastrophy if File.exist?(output) and not force puts "Error: file #{output} already exists. Use --force if you want to overwrite it" else content = File.read(template) backup_and_write output, content puts "YML resume template generated in #{output}" end end |
.json(opts, argv) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/resme/cli/command_semantics.rb', line 152 def self.json opts, argv output = opts[:output] || "resume-#{Date.today}.json" template = File.join(File.dirname(__FILE__), "/../templates/resume.json.erb") render argv, template, output puts "Resume generated in #{output}" end |
.man(opts = nil, argv = []) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/resme/cli/command_semantics.rb', line 22 def self.man opts = nil, argv = [] path = File.join(File.dirname(__FILE__), "/../../../README.md") file = File.open(path, "r") contents = file.read puts contents end |
.md(opts, argv) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/resme/cli/command_semantics.rb', line 136 def self.md opts, argv output = opts[:output] || "resume-#{Date.today}.md" template = File.join(File.dirname(__FILE__), "/../templates/resume.md.erb") render argv, template, output puts "Resume generated in #{output}" end |
.org(opts, argv) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/resme/cli/command_semantics.rb', line 144 def self.org opts, argv output = opts[:output] || "resume-#{Date.today}.org" template = File.join(File.dirname(__FILE__), "/../templates/resume.org.erb") render argv, template, output puts "Resume generated in #{output}" end |
.reps(all_commands, argv) ⇒ Object
read-eval-print step
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/resme/cli/command_semantics.rb', line 62 def self.reps all_commands, argv if argv == [] or argv[0] == "--help" or argv[0] == "-h" CommandSemantics.help exit 0 else command = argv[0] syntax_and_semantics = all_commands[command.to_sym] if syntax_and_semantics opts = syntax_and_semantics[0] function = syntax_and_semantics[1] begin parser = Slop::Parser.new(opts) result = parser.parse(argv[1..-1]) = result.to_hash arguments = result.arguments eval "CommandSemantics::#{function}(options, arguments)" rescue Slop::Error => e puts "#{APPNAME}: #{e}" rescue Exception => e puts e end else puts "#{APPNAME}: '#{command}' is not a valid command. See '#{APPNAME} help'" end end end |