Class: Ace::Task::CLI::Commands::Create

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

Overview

ace-support-cli Command class for ace-task create

Instance Method Summary collapse

Instance Method Details

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



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
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
118
119
120
121
122
123
124
125
126
# File 'lib/ace/task/cli/commands/create.rb', line 46

def call(title:, **options)
  dry_run = options[:"dry-run"]
  priority = options[:priority]
  tags_str = options[:tags]
  tags = tags_str ? tags_str.split(",").map(&:strip).reject(&:empty?) : []
  status = options[:status]
  estimate = options[:estimate]
  github_issue = parse_github_issue(options[:"github-issue"])
  child_of = options[:"child-of"]
  in_folder = options[:in]

  if status
    valid = Ace::Task::Atoms::TaskValidationRules::VALID_STATUSES
    unless valid.include?(status)
      raise Ace::Support::Cli::Error.new("Invalid status '#{status}'. Valid: #{valid.join(", ")}")
    end
  end

  if dry_run
    puts "Would create task:"
    puts "  Title:    #{title}"
    puts "  Status:   #{status}" if status
    puts "  Priority: #{priority}" if priority
    puts "  Estimate: #{estimate}" if estimate
    puts "  GitHub:   #{github_issue}" if github_issue
    puts "  Tags:     #{tags.join(", ")}" if tags.any?
    puts "  Parent:   #{child_of}" if child_of
    puts "  Folder:   #{in_folder}" if in_folder
    return
  end

  manager = Ace::Task::Organisms::TaskManager.new

  task = begin
    if child_of
      manager.create_subtask(
        child_of,
        title,
        status: status,
        priority: priority,
        tags: tags,
        estimate: estimate,
        github_issue: github_issue
      )
    else
      manager.create(
        title,
        status: status,
        priority: priority,
        tags: tags,
        estimate: estimate,
        github_issue: github_issue
      )
    end
  rescue Ace::Task::Organisms::TaskManager::CreateRetriesExhaustedError => e
    raise Ace::Support::Cli::Error, e.message
  end

  unless task
    raise Ace::Support::Cli::Error.new("Parent task '#{child_of}' not found") if child_of
    raise Ace::Support::Cli::Error.new("Failed to create task")
  end

  # Move to folder if specified
  if in_folder && !child_of
    task = manager.move(task.id, to: in_folder)
  end

  puts "Created task #{task.id}"
  puts "  Path: #{task.file_path}"
  if manager.last_update_note && !manager.last_update_note.strip.empty?
    puts "Info: #{manager.last_update_note}"
  end

  if options[:git_commit]
    Ace::Support::Items::Molecules::GitCommitter.commit(
      paths: [task.path],
      intention: "create task #{task.id}"
    )
  end
end