Class: Tefoji::CLI
- Inherits:
-
Object
- Object
- Tefoji::CLI
- Defined in:
- lib/tefoji/cli.rb
Constant Summary collapse
- DEFAULT_JIRA_URL =
'https://perforce.atlassian.net'
- JIRA_TEST_URL =
'https://perforce-sandbox-903.atlassian.net'
- DEFAULT_JIRA_AUTH_FILE =
"#{Dir.home}/.tefoji-auth.yaml"
- DOCUMENTATION =
<<~DOCOPT Generate Jira issues from YAML files. Usage: tefoji [--jira=URL] [--jira-test] [--jira-auth=FILE] [--jira-save-auth] [--jira-user=USER] [--jira-mock] [--no-notes] [--version] [--quiet|--debug] <issue_template> ... tefoji [--debug] [--quiet] --print-notes <issue_template> ... tefoji [--debug] [--quiet] --verify-only <issue_template> ... tefoji --version Options: -j --jira URL URL of the Jira instance (defaults to #{DEFAULT_JIRA_URL}) -J --jira-test Use the jira test environment (#{JIRA_TEST_URL}) -a --jira-auth=FILE Alternate YAML file with Base64-encoded 'username:application-token' string for Jira authentication -S --jira-save-auth Save/overwrite Base64-encoded yaml authentication to the jira-auth file (defaults to #{DEFAULT_JIRA_AUTH_FILE}) after succesfully authenticating to the Jira server. -u USER --jira-user USER User name for Jira -M --jira-mock Mock the Jira API. Useful only for development testing. -n --no-notes Do not print the template 'notes' section. This is mainly for tefoji wrappers that prefer to handle notes their own way. -p --print-notes Just print the notes for templates but do no other processing -v --version Show version -q --quiet Turn off (INFO) logging -D --debug Turn on debug (DEBUG) logging -V --verify-only Perform template verification and exit. -h --help Show this help DOCOPT
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
-
#run ⇒ Object
Iterate through issue templates, validating each.
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tefoji/cli.rb', line 42 def initialize(argv) @user_options = (argv) if @user_options['--version'] warn "tefoji version #{Gem.loaded_specs['tefoji'].version}" exit 0 end @user_options['--jira'] = JIRA_TEST_URL if @user_options['--jira-test'] @user_options['--jira'] = DEFAULT_JIRA_URL if @user_options['--jira'].nil? @user_options['jira-auth-string'] = nil @user_options['jira-auth-file'] = @user_options['--jira-auth'] || DEFAULT_JIRA_AUTH_FILE jira_auth_file = @user_options['jira-auth-file'] return unless File.file?(jira_auth_file) authentication = YAML.load_file(jira_auth_file) @user_options['jira-auth-string'] = authentication['jira-auth'] end |
Instance Method Details
#run ⇒ Object
Iterate through issue templates, validating each. If that goes well, generate Jira issues from them.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tefoji/cli.rb', line 65 def run tefoji = Tefoji.new(@user_options) template_uris = @user_options['<issue_template>'] # 1st pass, try to find each of the templates, verify each for syntax, # keep going even if we find errors in some templates error_count, templates = tefoji.yaml_syntax_check(template_uris) # 2nd pass, scan any templates that passed syntax-check for semantic problems exit 1 unless error_count.zero? if @user_options['--verify-only'] warn 'tefoji: no errors found.' exit 0 end if @user_options['--print-notes'] templates.each do |template| warn template[1]['notes'] if template[1].key?('notes') end exit 0 end # Retrieve any included templates templates.each do |template| template[:includes] = tefoji.includes(template) end # Looks like we're good to go, authenticate to jira and do the work tefoji.authenticate tefoji.save_authentication if @user_options['--jira-save-auth'] templates.each { |template| tefoji.run(template) } warn 'tefoji: completed sucessfully.' end |