Class: GitTree::TreeconfigCommand
- Inherits:
-
Object
- Object
- GitTree::TreeconfigCommand
- Includes:
- Logging
- Defined in:
- lib/commands/git_treeconfig.rb
Overview
A command to interactively create a user-level configuration file.
Constant Summary
Constants included from Logging
Logging::DEBUG, Logging::NORMAL, Logging::QUIET, Logging::VERBOSE
Instance Method Summary collapse
-
#initialize ⇒ TreeconfigCommand
constructor
A new instance of TreeconfigCommand.
- #run ⇒ Object
Methods included from Logging
#log, #log_stdout, verbosity, verbosity=
Constructor Details
#initialize ⇒ TreeconfigCommand
Returns a new instance of TreeconfigCommand.
11 12 13 14 15 16 |
# File 'lib/commands/git_treeconfig.rb', line 11 def initialize $PROGRAM_NAME = 'git-treeconfig' @cli = HighLine.new @config_path = GitTree::Config.default_config_path @existing_config = File.exist?(@config_path) ? YAML.load_file(@config_path) : {} end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/commands/git_treeconfig.rb', line 18 def run @cli.say "Welcome to git-tree configuration." @cli.say "This utility will help you create a configuration file at: #{@config_path}" @cli.say "Press Enter to accept the default value in brackets." @cli.say "" defaults = GitTree::Config.new new_config = {} new_config['git_timeout'] = @cli.ask("Git command timeout in seconds? ", Integer) do |q| q.default = @existing_config.fetch('git_timeout', defaults.git_timeout) end new_config['verbosity'] = @cli.ask("Default verbosity level (0=quiet, 1=normal, 2=verbose)? ", Integer) do |q| q.default = @existing_config.fetch('verbosity', defaults.verbosity) q.in = 0..2 end roots_str = @cli.ask("Default root directories (space-separated)? ", String) do |q| q.default = @existing_config.fetch('default_roots', defaults.default_roots).join(' ') end new_config['default_roots'] = roots_str.split File.write(@config_path, new_config.to_yaml) @cli.say "" @cli.say @cli.color("Configuration saved to #{@config_path}", :green) end |