Class: DiscourseCli::Commands::Config
- Defined in:
- lib/discourse_cli/commands/config.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
Class Method Details
.config_path ⇒ Object
9 10 11 |
# File 'lib/discourse_cli/commands/config.rb', line 9 def self.config_path DiscourseCli::Config.config_path end |
Instance Method Details
#list ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/discourse_cli/commands/config.rb', line 33 def list data = load_file sites = data["sites"] || {} default_site = data["default"] if sites.empty? puts "No sites configured. Run `dsc config set` to add one." return end sites.each do |name, cfg| marker = name == default_site ? " (default)" : "" puts "#{name}#{marker}" puts " host: #{cfg["host"]}" puts " api_username: #{cfg["api_username"]}" puts end end |
#set ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/discourse_cli/commands/config.rb', line 18 def set data = load_file data["sites"] ||= {} data["default"] ||= [:site] data["sites"][[:site]] = { "host" => [:host], "api_key" => [:"api-key"], "api_username" => [:"api-username"], } FileUtils.mkdir_p(File.dirname(self.class.config_path)) File.write(self.class.config_path, YAML.dump(data)) formatter.print_success("Saved config for site '#{[:site]}'") end |