Class: Hackpad::Cli::Config
- Inherits:
-
ConfigStruct
- Object
- ConfigStruct
- Hackpad::Cli::Config
- Includes:
- Cliprompt
- Defined in:
- lib/hackpad/cli/config.rb
Instance Method Summary collapse
- #change_default ⇒ Object
- #patch_1 ⇒ Object
- #set_defaults ⇒ Object
- #setup ⇒ Object
- #workspaces ⇒ Object
Instance Method Details
#change_default ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/hackpad/cli/config.rb', line 35 def change_default values = {} values['use_colors'] = use_colors values['workspace'] = ask 'What workspace do you want to use as default from now on?', choices: workspaces.map(&:name), default: workspace, aslist: true write values end |
#patch_1 ⇒ Object
45 46 47 48 49 |
# File 'lib/hackpad/cli/config.rb', line 45 def patch_1 if File.exist? File.join(basedir, "#{workspace}.yml") FileUtils.mv File.join(basedir, "#{workspace}.yml"), File.join(basedir, workspace, 'config.yml') end end |
#set_defaults ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/hackpad/cli/config.rb', line 10 def set_defaults super self.refresh ||= false self.urls ||= false self.workspace ||= 'default' setio @input, @output patch_1 end |
#setup ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/hackpad/cli/config.rb', line 19 def setup values = {} output.puts Paint['Create a new hackpad-cli configuration:', :blue] values['use_colors'] = guess 'HPCLI_COLORS', 'Do you want a colored output?', 'Yn' values['workspace'] = guess 'HPCLI_WORKSPACE', 'What is the name of the default workspace?', 'default' write values end |
#workspaces ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/hackpad/cli/config.rb', line 27 def workspaces w = Dir.glob(File.join(self.basedir, '*', 'config.yml')).reduce([]) do |a, path| a << OpenStruct.new(name: File.basename(File.dirname(path)), site: YAML.load_file(path)['site']) a end w.sort_by { |s| s.name } end |