lib/itch_rewards/cli.rb in itch_rewards-0.1.2 vs lib/itch_rewards/cli.rb in itch_rewards-0.1.3
- old
+ new
@@ -95,10 +95,20 @@
class Setup < Dry::CLI::Command
include Helper
include AuthOptions
@options = @options.reject {|opt| [:cookies, :interactive].include? opt.name }
+ def write_config(path, options)
+ require 'erb'
+ client = authenticated_client!(options)
+
+ games = client.game_map.map.values
+ template = File.read(File.join(__dir__, 'templates/reward_config.yml.erb'))
+
+ File.write(path, ERB.new(template, trim_mode: '-').result(binding))
+ end
+
desc "Save cookies for itch.io and create reward config example file"
def call(**options)
options[:cookies] ||= cli.ask("Where would you like to store your login cookies? ", default: ".itch-cookies.yml")
options[:interactive] = true
@@ -112,11 +122,11 @@
if !File.exist? config_path
result = cli.yes?("Config file #{config_path} does not exist, would you like to create it?")
if result
- Rewards.write_config(config_path, options)
+ write_config(config_path, options)
cli.say "Config file written to #{config_path}"
end
else
cli.warn "Config file #{config_path} already exists, skipping..."
end
@@ -144,19 +154,9 @@
include Helper
def self.show_rewards(game)
cli.say "Rewards for #{game.name} (id: #{game.id})"
table = objects_to_table(game.rewards.list)
cli.say render_table(table)
- end
-
- def self.write_config(path, options)
- require 'erb'
- client = authenticated_client!(options)
-
- games = client.game_map.map.values
- template = File.read(File.join(__dir__, 'templates/reward_config.yml.erb'))
-
- File.write(options[:config], ERB.new(template, trim_mode: '-').result(binding))
end
def self.load_config(path)
YAML.load_file(path)
rescue YAML::ParseError => e