Class: SplttyCLI::Commands::MethodsAdd
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- SplttyCLI::Commands::MethodsAdd
- Defined in:
- lib/spltty_cli/commands/methods_add.rb
Overview
spltty methods add — add or update a payment method in the config. Only
the properties you pass are set; existing ones are preserved.
Instance Method Summary collapse
Instance Method Details
#call(name:, **opts) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spltty_cli/commands/methods_add.rb', line 25 def call(name:, **opts) config = SplttyCLI.load_config(opts) existed = config.payment_methods.key?(name) entry = (config.payment_methods[name] ||= {}) entry["slug"] = opts[:slug] unless blank?(opts[:slug]) entry["paid_by"] = opts[:paid_by] unless blank?(opts[:paid_by]) entry["responsible"] = opts[:responsible] unless blank?(opts[:responsible]) entry["bill_day"] = parse_bill_day(opts[:bill_day]) unless blank?(opts[:bill_day]) config.save puts "#{existed ? 'Updated' : 'Added'} payment method #{name.inspect}: #{entry.to_json}" rescue Config::Error => e warn "spltty methods add: #{e.}" exit 1 end |