Class: Strata::CLI::SubCommands::Branch

Inherits:
Thor
  • Object
show all
Includes:
Guard, Output
Defined in:
lib/strata/cli/sub_commands/branch.rb

Constant Summary

Constants included from Output

Output::THEME

Constants included from Guard

Guard::ALLOWED_COMMANDS

Instance Method Summary collapse

Methods included from Output

format, pastel, print_error, #print_error, print_hint, #print_hint, print_info, #print_info, print_status, #print_status, print_success, #print_success, print_warning, #print_warning, shell_for, thor_color

Methods included from Guard

#invoke_command

Instance Method Details

#checkout(branch_name) ⇒ Object



41
42
43
44
# File 'lib/strata/cli/sub_commands/branch.rb', line 41

def checkout(branch_name)
  branch_name = Utils::Git.checkout_branch(branch_name)
  print_success("Checked out branch '#{branch_name}'.")
end

#create(branch_name) ⇒ Object



35
36
37
38
# File 'lib/strata/cli/sub_commands/branch.rb', line 35

def create(branch_name)
  branch_name = Utils::Git.create_and_checkout_branch(branch_name)
  print_success("Created and checked out branch '#{branch_name}'.")
end

#deleteObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/strata/cli/sub_commands/branch.rb', line 48

def delete
  branch_id = branch_to_delete
  config = CLI.config.get_for_environment(options[:environment])
  validate_delete_configuration(config)

  return unless confirm_branch_deletion(branch_id)

  client = API::Client.new(config["server"], config["api_key"])
  server_deleted = client.delete_branch(config["project_id"], branch_id)
  print_warning("Branch '#{branch_id}' was not found on Strata server. Deleting local branch only.") unless server_deleted

  delete_local_branch(branch_id)

  print_success("Deleted branch '#{branch_id}'.")
end

#listObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/strata/cli/sub_commands/branch.rb', line 21

def list
  config = CLI.config.get_for_environment(options[:environment])
  local_branch_names = Utils::Git.local_branches
  server_branches = fetch_server_branches(config)

  rows = branch_rows(local_branch_names, server_branches)
  if rows.empty?
    print_info("No local or Strata server branches found.")
  else
    rows.each { |row| print_info(row) }
  end
end