Module: DevContext::Commands::Stashes

Included in:
DevContext::CLI
Defined in:
lib/dev_context/commands/stashes.rb

Instance Method Summary collapse

Instance Method Details

#cmd_stashesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dev_context/commands/stashes.rb', line 6

def cmd_stashes
  args = argv.dup
  show_list = false
  parser = OptionParser.new
  parser.on("-l", "--list", "Show stash entry titles per repo") { show_list = true }
  parser.parse!(args)
  pattern = args.shift
  return usage_error("dx stashes [--list] [PATTERN]") unless args.empty?

  rows = known_repo_stash_rows(pattern: pattern)
  if rows.empty?
    out.puts("No repos with stashes")
    return 0
  end

  render_stash_table(rows)
  return 0 unless show_list

  out.puts
  rows.each do |row|
    out.puts("#{display_path(row[:path])}:")
    row[:entries].each { |entry| out.puts("  - #{entry}") }
  end
  0
rescue OptionParser::InvalidOption => e
  err.puts("dx: #{e.message}")
  usage_error("dx stashes [--list] [PATTERN]")
end