Class: Ace::Retro::CLI::Commands::Update

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/retro/cli/commands/update.rb

Overview

ace-support-cli Command class for ace-retro update

Instance Method Summary collapse

Instance Method Details

#call(ref:, **options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ace/retro/cli/commands/update.rb', line 44

def call(ref:, **options)
  set_args = Array(options[:set])
  add_args = Array(options[:add])
  remove_args = Array(options[:remove])
  move_to = options[:move_to]

  if set_args.empty? && add_args.empty? && remove_args.empty? && move_to.nil?
    warn "Error: at least one of --set, --add, --remove, or --move-to is required"
    warn ""
    warn "Usage: ace-retro update REF [--set K=V]... [--add K=V]... [--remove K=V]... [--move-to FOLDER]"
    raise Ace::Support::Cli::Error.new("No update operations specified")
  end

  set_hash = parse_kv_pairs(set_args)
  add_hash = parse_kv_pairs(add_args)
  remove_hash = parse_kv_pairs(remove_args)

  manager = Ace::Retro::Organisms::RetroManager.new
  retro = manager.update(ref, set: set_hash, add: add_hash, remove: remove_hash, move_to: move_to)

  unless retro
    raise Ace::Support::Cli::Error.new("Retro '#{ref}' not found")
  end

  if move_to
    folder_info = retro.special_folder || "root"
    puts "Retro updated: #{retro.id} #{retro.title}#{folder_info}"
  else
    puts "Retro updated: #{retro.id} #{retro.title}"
  end

  if options[:git_commit]
    commit_paths = move_to ? [manager.root_dir] : [retro.path]
    intention = if move_to
      "update retro #{retro.id} and move to #{retro.special_folder || "root"}"
    else
      "update retro #{retro.id}"
    end
    Ace::Support::Items::Molecules::GitCommitter.commit(
      paths: commit_paths,
      intention: intention
    )
  end
end