Class: Lightning::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/generator.rb

Class Method Summary collapse

Class Method Details

.bash_generator(commands) ⇒ 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
# File 'lib/lightning/generator.rb', line 16

def bash_generator(commands)
  body = "  #### This file was generated by Lightning. ####\n  #LBIN_PATH=\"$PWD/bin/\" #only use for development\n  LBIN_PATH=\"\" \n  \n  INIT\n  commands.each do |e|\n    body += <<-EOS\n      \n      \#{'#' + e['description'] if e['description']}\n      \#{e['name']} () {\n        if [ -z \"$1\" ]; then\n          echo \"No arguments given\"\n          return\n        fi\n        FULL_PATH=\"`${LBIN_PATH}lightning-full_path \#{e['path_key']} $@`\#{e['post_path'] if e['post_path']}\"\n        if [ $1 == '\#{Lightning::TEST_FLAG}' ]; then\n          CMD=\"\#{e['map_to']} '$FULL_PATH'\#{' '+ e['add_to_command'] if e['add_to_command']}\"\n          echo $CMD\n        else\n          \#{e['map_to']} \"$FULL_PATH\"\#{' '+ e['add_to_command'] if e['add_to_command']}\n        fi\n      }\n      complete -o default -C \"${LBIN_PATH}lightning-complete \#{e['path_key']}\" \#{e['name']}\n    EOS\n  end\n  body.gsub(/^\\s{6,10}/, '')\nend\n"

.generate(*args) ⇒ Object



11
12
13
14
# File 'lib/lightning/generator.rb', line 11

def generate(*args)
  shell = args.shift
  send("#{shell}_generator", *args)
end

.generate_completionsObject



5
6
7
8
9
# File 'lib/lightning/generator.rb', line 5

def generate_completions
  output = generate(Lightning.config[:shell], Lightning.config[:commands])
  File.open(Lightning.config[:generated_file], 'w'){|f| f.write(output) }
  output
end