Class: Lightning::Generator
- Inherits:
-
Object
- Object
- Lightning::Generator
- Defined in:
- lib/lightning/generator.rb
Class Method Summary collapse
- .bash_generator(commands) ⇒ Object
- .generate(*args) ⇒ Object
- .generate_completions(generated_file = nil) ⇒ Object
Class Method Details
.bash_generator(commands) ⇒ Object
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 |
# File 'lib/lightning/generator.rb', line 17 def bash_generator(commands) body = <<-INIT #### This file was generated by Lightning. #### #LBIN_PATH="$PWD/bin/" #only use for development LBIN_PATH="" INIT commands.each do |e| body += <<-EOS #{'#' + e['description'] if e['description']} #{e['name']} () { if [ -z "$1" ]; then echo "No arguments given" return fi FULL_PATH="`${LBIN_PATH}lightning-full_path #{e['name']} $@`#{e['post_path'] if e['post_path']}" if [ $1 == '#{Lightning::TEST_FLAG}' ]; then CMD="#{e['map_to']} '$FULL_PATH'#{' '+ e['add_to_command'] if e['add_to_command']}" echo $CMD else #{e['map_to']} "$FULL_PATH"#{' '+ e['add_to_command'] if e['add_to_command']} fi } complete -o default -C "${LBIN_PATH}lightning-complete #{e['name']}" #{e['name']} EOS end body.gsub(/^\s{6,10}/, '') end |
.generate(*args) ⇒ Object
12 13 14 15 |
# File 'lib/lightning/generator.rb', line 12 def generate(*args) shell = args.shift send("#{shell}_generator", *args) end |
.generate_completions(generated_file = nil) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/lightning/generator.rb', line 5 def generate_completions(generated_file=nil) generated_file ||= Lightning.config[:generated_file] output = generate(Lightning.config[:shell], Lightning.config[:commands]) File.open(generated_file, 'w'){|f| f.write(output) } output end |