class SimpleCommander::CLI
Constants
- DEFAULT_PATH
- HELPERS_PATH
- TEMPLATE_PATH
Attributes
config_file[RW]
Public Class Methods
new(path=DEFAULT_PATH)
click to toggle source
# File lib/simple_commander/cli.rb, line 32 def initialize(path=DEFAULT_PATH) @config_file = path init_yaml_config if !File.file?(@config_file) end
Public Instance Methods
exec_path()
click to toggle source
if set the bin/executable* file of any program created will be put in this folder
# File lib/simple_commander/cli.rb, line 89 def exec_path path = YAML.load_file(@config_file)[:exec_path] if(path.empty?) return false else return path end end
init(path='./')
click to toggle source
# File lib/simple_commander/cli.rb, line 42 def init(path='./') if path local_path = File.expand_path(path) else local_path = File.expand_path('./') end yml = YAML.load_file(@config_file) yml[:path] = local_path File.open(@config_file, 'w+'){|f| f.write(yml.to_yaml)} end
init_yaml_config()
click to toggle source
# File lib/simple_commander/cli.rb, line 37 def init_yaml_config yml = { path: "", exec_path: "" }.to_yaml File.open(@config_file, 'w+'){|f| f.write(yml)} end
new(*args)
click to toggle source
# File lib/simple_commander/cli.rb, line 58 def new(*args) sc_path = YAML.load_file(@config_file)[:path] raise UndefinedSCPath if !sc_path s_path = "#{sc_path}/#{args[0]}" fail InvalidProgram, "program #{args[0]} already exists!", caller if File.directory?(s_path) @program_name = args[0] @lib_path = "#{s_path}/lib" @helper_path = File.expand_path "#{s_path}" + "/../helpers" mkdir s_path mkdir "#{s_path}/bin" mkdir "#{s_path}/spec" mkdir "#{s_path}/lib" mkdir @helper_path mkdir "#{s_path}/lib/#{@program_name}" template "#{TEMPLATE_PATH}/lib.erb", "#{s_path}/lib/#{@program_name}.rb", binding template "#{TEMPLATE_PATH}/version.erb", "#{s_path}/lib/#{@program_name}/version.rb", binding template "#{TEMPLATE_PATH}/bin.erb", "#{s_path}/bin/#{@program_name}", binding FileUtils.chmod "+x", "#{s_path}/bin/#{@program_name}" copy "#{s_path}/bin/#{@program_name}", exec_path if exec_path copy "#{HELPERS_PATH}/io_helper.rb", "#{@helper_path}/io_helper.rb" copy "#{HELPERS_PATH}/http_helper.rb", "#{@helper_path}/http_helper.rb" end
set_exec_path(path)
click to toggle source
set exec path
# File lib/simple_commander/cli.rb, line 100 def set_exec_path(path) yml = YAML.load_file(@config_file) yml[:exec_path] = File.expand_path(path) File.open(@config_file, 'w+'){|f| f.write(yml.to_yaml)} end
show_config()
click to toggle source
# File lib/simple_commander/cli.rb, line 53 def show_config raise UndefinedSCPath if !File.file?(@config_file) say YAML.load_file(@config_file) end