Class: Jirify::Subcommands::Setup

Inherits:
Thor
  • Object
show all
Defined in:
lib/jirify/cli/setup.rb

Instance Method Summary collapse

Instance Method Details

#bash_completionObject



53
54
55
56
57
58
# File 'lib/jirify/cli/setup.rb', line 53

def bash_completion
  say "Updating #{Config.config_folder}/jirify.bash_completion.sh ...".blue
  Config.copy_bash_completion!

  say 'Done! You have to source the file again or open a new shell! :)'.green
end

#initObject



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
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jirify/cli/setup.rb', line 7

def init
  say 'Welcome! This will guide you through the configuration of the jirify CLI tool.'

  if Config.initialized?
    exit(0) unless yes? 'You seem to have already configured jirify. ' \
      'Do you want to continue and overwrite the current configuration? [Y/n]:'.yellow
  end

  username      = ask 'Enter username:'
  token         = ask 'Enter token (generate from https://id.atlassian.com):'
  site          = ask 'Enter JIRA url:'
  project       = ask 'Enter a comma-separated list of JIRA Project keys to filter by every time (1 required):'
  filter_labels = ask 'Enter a comma-separated list of labels to filter by every time (optional):'

  labels = filter_labels.split ', ' if filter_labels
  projects = project.split ', ' if project

  if projects.nil? or projects.empty?
    say "You must enter at least one project key!".red
    exit(0)
  end

  options = {
    'options' => {
      'username' => username,
      'token'    => token,
      'site'     => site,
      'projects'  => projects
    }
  }

  options['options']['filter_by_labels'] = labels unless labels.empty?

  Config.write(options)

  say 'Done!'.green
  say "If you want to enable bash completion, source #{Config.config_folder}/jirify.bash_completion.sh"
end

#projectsObject



62
63
64
65
66
67
68
69
# File 'lib/jirify/cli/setup.rb', line 62

def projects
  if options[:set].nil? || options[:set].empty?
    say 'Pass a list of projects to set with -s. Run "jira setup help projects" for more information.'.red
    exit(0)
  end

  Config.projects = options[:set]
end

#verboseObject



48
49
50
# File 'lib/jirify/cli/setup.rb', line 48

def verbose
  Config.verbose = options[:enable]
end