Class: MyHelp::CLI

Inherits:
Thor
  • Object
show all
Includes:
GetConfig
Defined in:
lib/my_help/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetConfig

#get_config

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/my_help/cli.rb', line 11

def exit_on_failure?
  true
end

Instance Method Details

#delete(*args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/my_help/cli.rb', line 86

def delete(*args)
  c = get_config
  help_name = args[0]
  help_file = File.join(c[:local_help_dir], help_name + c[:ext])
  puts "Are you sure to delete #{help_file}? [YN]"
  responce = $stdin.gets.chomp
  if responce.upcase[0] == "Y"
    Modify.new(c).delete(help_file)
  else
    puts "Leave #{help_file} exists."
  end
end

#edit(*args) ⇒ Object



68
69
70
71
72
# File 'lib/my_help/cli.rb', line 68

def edit(*args)
  c = get_config
  help_name = args[0]
  Modify.new(c).edit(help_name)
end

#helloObject



101
102
103
104
# File 'lib/my_help/cli.rb', line 101

def hello
  name = $stdin.gets.chomp
  puts("Hello #{name}.")
end

#init(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/my_help/cli.rb', line 27

def init(*args)
  config = get_config # for using methods in Config
  #config.ask_default
  init = Init.new(config)
  raise "Local help dir exist." if init.help_dir_exist?
  puts "Choose default markup '.org' [Y or .md]? "
  response = $stdin.gets.chomp
  config.configure(:ext => response) unless response.upcase[0] == "Y"
  init.mk_help_dir
  config.save_config
  init.cp_templates
  puts "If you want change editor use my_help set editor code."
end

#list(*args) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/my_help/cli.rb', line 57

def list(*args)
  config = get_config
  help_dir = options["help_dir"] || config[:local_help_dir]
  layer = options["layer"] || 1
  puts List.new(help_dir,
                config[:ext],
                layer).list(*args.join(" "))
end

#new(*args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/my_help/cli.rb', line 76

def new(*args)
  c = get_config
  help_name = args[0]
  help_file = File.join(c[:local_help_dir], help_name + c[:ext])
  Modify.new(c).new(help_file)
  #     puts res.stdout
end

#set(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/my_help/cli.rb', line 43

def set(*args)
  config = get_config # for using methods in Config
  key = args[0] || ""
  config.configure(key.to_sym => args[1])
  config.save_config
  conf_file_path = config[:conf_file]
  puts "conf_file_path: %s" % conf_file_path
  puts File.read(conf_file_path)
end

#versionObject



18
19
20
# File 'lib/my_help/cli.rb', line 18

def version
  puts VERSION
end