Module: Rubyists::Linear::CLI::SubCommands
- Includes:
- WhatFor
- Included in:
- Issue, Team
- Defined in:
- lib/linear/cli/sub_commands.rb
Overview
The SubCommands module should be included in all commands with subcommands
Constant Summary
Constants included
from WhatFor
WhatFor::ALLOWED_PR_TYPES, WhatFor::PR_TYPES, WhatFor::PR_TYPE_SELECTIONS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from WhatFor
#ask_for_projects, #ask_or_edit, #cancelled_state_for, #comment_for, #completed_state_for, #description_for, #editor_for, #labels_for, #pr_description_for, #pr_scope_for, #pr_title_for, #pr_type_for, #project_for, #project_scores, #reason_for, #team_for, #title_for
Class Method Details
.included(mod) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/linear/cli/sub_commands.rb', line 14
def self.included(mod)
mod.instance_eval do
def const_added(const)
return unless const == :ALIASES
Rubyists::Linear::CLI.load_and_register! self
end
end
end
|
Instance Method Details
#ask_for_team ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/linear/cli/sub_commands.rb', line 29
def ask_for_team
teams = Rubyists::Linear::Team.mine
if teams.size == 1
logger.info('Only one team found, using it', team: teams.first.name)
teams.first
elsif teams.empty?
logger.error('No teams found for you. Please join a team or pass an existing team ID.')
raise SmellsBad, 'No team given and none found for you (try joining a team or use a team id from `lc teams --no-mine`)' else
choose_a_team! teams
end
end
|
#branch_for(branch_name) ⇒ Object
50
51
52
|
# File 'lib/linear/cli/sub_commands.rb', line 50
def branch_for(branch_name)
git.branches.local.detect { |b| b.name == branch_name } || git.branch(branch_name)
end
|
#choose_a_team!(teams) ⇒ Object
24
25
26
27
|
# File 'lib/linear/cli/sub_commands.rb', line 24
def choose_a_team!(teams)
key = prompt.select('Choose a team', teams.to_h { |t| [t.name, t.key] })
Rubyists::Linear::Team.find key
end
|
#current_branch ⇒ Object
46
47
48
|
# File 'lib/linear/cli/sub_commands.rb', line 46
def current_branch
git.current_branch
end
|
#default_branch ⇒ Object
71
72
73
|
# File 'lib/linear/cli/sub_commands.rb', line 71
def default_branch
@default_branch ||= Git.default_branch git.remote.url
end
|
#git ⇒ Object
64
65
66
67
68
69
|
# File 'lib/linear/cli/sub_commands.rb', line 64
def git
@git ||= Git.open('.')
rescue ArgumentError => e
logger.error('Your current directory is not a git repository!', error: e)
exit 121
end
|
#prompt ⇒ Object
42
43
44
|
# File 'lib/linear/cli/sub_commands.rb', line 42
def prompt
@prompt ||= CLI.prompt
end
|
#pull_or_push_new_branch!(branch_name) ⇒ Object
Horrible way to do this, but it is working for now
55
56
57
58
59
60
61
62
|
# File 'lib/linear/cli/sub_commands.rb', line 55
def pull_or_push_new_branch!(branch_name)
git.pull
rescue Git::FailedError
prompt.warn("Upstream branch not found, pushing local #{branch_name} to origin")
git.push('origin', branch_name)
`git branch --set-upstream-to=origin/#{branch_name} #{branch_name}`
prompt.ok("Set upstream to origin/#{branch_name}")
end
|