lib/itch_rewards/cli.rb in itch_rewards-0.1.3 vs lib/itch_rewards/cli.rb in itch_rewards-0.1.4

- old
+ new

@@ -75,10 +75,16 @@ def render_table(table) return "No data" unless table table.render(:unicode, multiline: true, padding: [0,1], resize: false, border: { style: :green }) end + + def 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 end module Commands extend Dry::CLI::Registry @@ -148,25 +154,10 @@ end end end module Rewards - extend self - 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.load_config(path) - YAML.load_file(path) - rescue YAML::ParseError => e - cli.error("Config file (#{path}) is not valid yaml") - exit 1 - end - class List < Dry::CLI::Command include AuthOptions include Helper desc "List all rewards for a game" @@ -185,11 +176,11 @@ end client = authenticated_client!(options) game = options[:id] ? client.game(options[:id]) : client.game(name: options[:name]) - Rewards.show_rewards(game) + show_rewards(game) end end class Update < Dry::CLI::Command include AuthOptions @@ -236,31 +227,38 @@ end end rewards.save reward_list - Rewards.show_rewards(game) + show_rewards(game) end end class Automate < Dry::CLI::Command include Helper include AuthOptions + def load_config(path) + YAML.load_file(path) + rescue YAML::ParseError => e + cli.error("Config file (#{path}) is not valid yaml") + exit 1 + end + desc "Update reward quantity and description from configuration file" option :config, required: true, desc: "Path to config file", default: "itch-reward-config.yml" option :save, type: :boolean, desc: "Saves changes when enabled. Otherwise, dry-run and show result", default: false - + def call(**options) client = authenticated_client!(options) if !File.exist? options[:config] cli.error("Config file #{options[:config]} does not exist") exit 1 end - config = Rewards.load_config(options[:config]) + config = load_config(options[:config]) unless config["games"].is_a? Hash cli.error("No games configured for rewards updates in config file") exit 1 end