class Bashly::Commands::Add
Public Instance Methods
colors_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 44 def colors_command safe_copy_lib "colors.sh" end
comp_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 52 def comp_command format = args['FORMAT'] output = args['OUTPUT'] case format when "function" save_comp_function output when "yaml" save_comp_yaml output when "script" save_comp_script output else raise Error, "Unrecognized format: #{format}" end end
config_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 40 def config_command safe_copy_lib "config.sh" end
lib_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 36 def lib_command safe_copy_lib "sample_function.sh" end
strings_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 32 def strings_command safe_copy asset("templates/strings.yml"), "#{Settings.source_dir}/bashly-strings.yml" end
yaml_command()
click to toggle source
# File lib/bashly/commands/add.rb, line 48 def yaml_command safe_copy_lib "yaml.sh" end
Private Instance Methods
command()
click to toggle source
# File lib/bashly/commands/add.rb, line 98 def command @command ||= Models::Command.new config end
completions()
click to toggle source
# File lib/bashly/commands/add.rb, line 102 def completions @completions ||= command.completion_data end
completions_function()
click to toggle source
# File lib/bashly/commands/add.rb, line 110 def completions_function @completions_function ||= command.completion_function end
completions_script()
click to toggle source
# File lib/bashly/commands/add.rb, line 106 def completions_script @completions_script ||= command.completion_script end
config()
click to toggle source
# File lib/bashly/commands/add.rb, line 94 def config @config ||= Config.new "#{Settings.source_dir}/bashly.yml" end
deep_copy(source, target)
click to toggle source
# File lib/bashly/commands/add.rb, line 88 def deep_copy(source, target) target_dir = File.dirname target FileUtils.mkdir_p target_dir unless Dir.exist? target_dir FileUtils.cp source, target end
safe_copy(source, target)
click to toggle source
# File lib/bashly/commands/add.rb, line 75 def safe_copy(source, target) if !Dir.exist? Settings.source_dir raise InitError, "Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist\nRun !txtpur!bashly init!txtrst! first" end if File.exist? target and !args['--force'] say "skipped !txtgrn!#{target}!txtrst! (exists)" else deep_copy source, target say "created !txtgrn!#{target}" end end
safe_copy_lib(libfile)
click to toggle source
# File lib/bashly/commands/add.rb, line 71 def safe_copy_lib(libfile) safe_copy asset("templates/lib/#{libfile}"), "#{Settings.source_dir}/lib/#{libfile}" end
save_comp_function(name = nil)
click to toggle source
# File lib/bashly/commands/add.rb, line 132 def save_comp_function(name = nil) name ||= "send_completions" target_dir = "#{Settings.source_dir}/lib" filename = "#{target_dir}/#{name}.sh" FileUtils.mkdir_p target_dir unless Dir.exist? target_dir File.write filename, completions_function say "created !txtgrn!#{filename}" say "" say "In order to use it in your script, create a command or a flag (for example: !txtgrn!#{command.name} completions!txtrst! or !txtgrn!#{command.name} --completions!txtrst!) that calls the !txtgrn!#{name}!txtrst! function." say "Your users can then run something like this to enable completions:" say "" say " !txtpur!$ eval \"$(#{command.name} completions)\"" end
save_comp_script(filename = nil)
click to toggle source
# File lib/bashly/commands/add.rb, line 122 def save_comp_script(filename = nil) filename ||= "#{Settings.target_dir}/completions.bash" File.write filename, completions_script say "created !txtgrn!#{filename}" say "" say "In order to enable completions, run:" say "" say " !txtpur!$ source #{filename}" end
save_comp_yaml(filename = nil)
click to toggle source
# File lib/bashly/commands/add.rb, line 114 def save_comp_yaml(filename = nil) filename ||= "#{Settings.target_dir}/completions.yml" File.write filename, completions.to_yaml say "created !txtgrn!#{filename}" say "" say "This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem." end