Class: Ace::Idea::CLI::Commands::Update

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

Overview

ace-support-cli Command class for ace-idea 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/idea/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-idea 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::Idea::Organisms::IdeaManager.new
  idea = manager.update(ref, set: set_hash, add: add_hash, remove: remove_hash, move_to: move_to)

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

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

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