Class: Ace::Retro::CLI::Commands::Create

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

Overview

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

Instance Method Summary collapse

Instance Method Details

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



40
41
42
43
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
# File 'lib/ace/retro/cli/commands/create.rb', line 40

def call(title: nil, **options)
  type = options[:type]
  tags_str = options[:tags]
  move_to = options[:"move-to"]
  dry_run = options[:"dry-run"]

  tags = tags_str ? tags_str.split(",").map(&:strip).reject(&:empty?) : []

  unless title
    warn "Error: title is required"
    warn ""
    warn "Usage: ace-retro create TITLE [--type TYPE] [--tags T1,T2] [--move-to FOLDER]"
    raise Ace::Support::Cli::Error.new("Title required")
  end

  if dry_run
    puts "Would create retro:"
    puts "  Title:    #{title}"
    puts "  Type:     #{type || "standard"}"
    puts "  Tags:     #{tags.any? ? tags.join(", ") : "(none)"}"
    puts "  Folder:   #{move_to ? "_#{move_to.delete_prefix("_")}" : "(root)"}"
    return
  end

  manager = Ace::Retro::Organisms::RetroManager.new
  retro = manager.create(
    title,
    type: type,
    tags: tags,
    move_to: move_to
  )

  folder_info = retro.special_folder ? " (#{retro.special_folder})" : ""
  puts "Retro created: #{retro.id} #{retro.title}#{folder_info}"
  puts "  Path: #{retro.file_path}"

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