Method: Plan::CLI.create

Defined in:
lib/plan/cli.rb

.create(paths) ⇒ Object

create a new todo



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/plan/cli.rb', line 98

def create(paths)
  if paths.empty?
    raise Plan::Advice.new('please provide something to create')
  end
  # descend to the right depth
  item = path_tree.descend(paths[0..-2])
  # and then create
  if item.children.any? { |c| !c.hidden? && c.has_label?(paths[-1]) }
    raise Plan::Advice.new("duplicate entry at level: #{paths[-1]}")
  else
    item.children << Item.new(paths[-1])
    save_path_tree
    # and say what happened
    print_depth item
  end
end