Class: SimpleCommander::CLI

Inherits:
Object show all
Includes:
IO_helper
Defined in:
lib/simple_commander/cli.rb

Defined Under Namespace

Classes: UndefinedSCPath

Constant Summary collapse

DEFAULT_PATH =
"#{File.dirname(__FILE__)}/config.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IO_helper

#cli_exist?, #command_exist?, #copy, #copy_dir, #have_subcommands?, #in_file?, #mkdir, #rm_block, #rm_dir, #rm_file, #rm_string, #run_cmd, #subcommand_exist?, #template, #write_after, #write_end, #write_start

Constructor Details

#initialize(path = DEFAULT_PATH) ⇒ CLI

Returns a new instance of CLI.



22
23
24
# File 'lib/simple_commander/cli.rb', line 22

def initialize(path=DEFAULT_PATH)
  @config_file = path
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



9
10
11
# File 'lib/simple_commander/cli.rb', line 9

def config_file
  @config_file
end

Instance Method Details

#init(path = './') ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/simple_commander/cli.rb', line 26

def init(path='./')
  if path
    local_path = File.expand_path(path)
  else
    local_path = File.expand_path('./')
  end

  yml = { path: local_path }.to_yaml
  File.open(@config_file, 'w+'){|f| f.write(yml)}
end

#new(*args) ⇒ Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_commander/cli.rb', line 41

def new(*args)
  sc_path = YAML.load_file(@config_file)[:path]
  raise UndefinedSCPath if !sc_path
  s_path = "#{sc_path}/#{args[0]}"
  raise StandardError "program #{args[0]} already exists!"  if File.directory?(s_path)
  @program_name = args[0]
  mkdir s_path 
  mkdir "#{s_path}/bin"
  mkdir "#{s_path}/spec"
  mkdir "#{s_path}/lib"
  mkdir "#{s_path}/lib/#{@program_name}"
  template './templates/lib.erb',
    "#{s_path}/lib/#{@program_name}.rb"
  template './templates/version.erb',
    "#{s_path}/lib/#{@program_name}/version.rb"
  template './templates/bin.erb',
    "#{s_path}/bin/#{@program_name}"
end

#show_configObject



37
38
39
# File 'lib/simple_commander/cli.rb', line 37

def show_config
  say YAML.load_file(@config_file)
end