Class: Ace::Task::CLI::Commands::Update
- Inherits:
-
Support::Cli::Command
- Object
- Support::Cli::Command
- Ace::Task::CLI::Commands::Update
- Includes:
- Support::Cli::Base
- Defined in:
- lib/ace/task/cli/commands/update.rb
Overview
ace-support-cli Command class for ace-task update
Instance Method Summary collapse
Instance Method Details
#call(ref:, **options) ⇒ Object
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ace/task/cli/commands/update.rb', line 53 def call(ref:, **) set_args = Array([:set]) add_args = Array([:add]) remove_args = Array([:remove]) move_to = [:move_to] move_as_child = [:move_as_child_of] position_arg = [:position] has_any_op = !set_args.empty? || !add_args.empty? || !remove_args.empty? || move_to || move_as_child || position_arg unless has_any_op warn "Error: at least one of --set, --add, --remove, --move-to, --move-as-child-of, or --position is required" warn "" warn "Usage: ace-task update REF [--set K=V]... [--move-to FOLDER] [--position first|last|after:REF|before:REF]" raise Ace::Support::Cli::Error.new("No update operations specified") end if move_to && move_as_child raise Ace::Support::Cli::Error.new("Cannot use --move-to and --move-as-child-of together") end set_hash = parse_kv_pairs(set_args) add_hash = parse_kv_pairs(add_args) remove_hash = parse_kv_pairs(remove_args) manager = Ace::Task::Organisms::TaskManager.new # Resolve --position into a set or remove operation if position_arg pos_value = resolve_position(position_arg, manager) set_hash["position"] = pos_value end task = manager.update(ref, set: set_hash, add: add_hash, remove: remove_hash, move_to: move_to, move_as_child_of: move_as_child) unless task raise Ace::Support::Cli::Error.new("Task '#{ref}' not found") end if move_as_child puts "Task reparented: #{task.id} #{task.title}" elsif move_to folder_info = task.special_folder || "root" puts "Task updated: #{task.id} #{task.title} → #{folder_info}" else puts "Task updated: #{task.id} #{task.title}" end puts "Info: #{manager.last_update_note}" if manager.last_update_note if [:git_commit] commit_paths = (move_to || move_as_child) ? [manager.root_dir] : [task.path] intention = if move_as_child "reparent task #{task.id}" elsif move_to "update task #{task.id} and move to #{task.special_folder || "root"}" else "update task #{task.id}" end Ace::Support::Items::Molecules::GitCommitter.commit( paths: commit_paths, intention: intention ) end end |