Class: TrelloFreestyler::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/trello_freestyler/cli.rb

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Layout/LineLength



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
45
46
47
48
49
50
51
52
53
# File 'lib/trello_freestyler/cli.rb', line 10

def self.parse(options)
  # DEFAULTS
  args = Options.new(nil, nil, nil, nil, nil, nil, nil)

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: trello_freestyler -k <KEY> -t <TOKEN> -b <BOARD_ID>'

    opts.on('-k', '--key KEY', String, 'REQUIRED - Developer Trello Key') do |i|
      args.key = i
    end

    opts.on('-t', '--token TOKEN', String, 'REQUIRED - Developer Trello Token') do |i|
      args.token = i
    end

    opts.on('-b', '--board_id BOARD_ID', String, 'REQUIRED - The Trello Board Id to export') do |i|
      args.board_id = i
    end

    opts.on('-a', '--actions ACTIONS', Array, "Override the list of Trello action types to dump: example 'createCard,updateCard'") do |i|
      args.action_types = i.join(',')
    end

    opts.on('-u', '--url TRELLO_URL', String, 'Override the default Trello API Url [https://api.trello.com/1]') do |i|
      args.url = i
    end

    opts.on('-o', '--output OUTPUT_FOLDER', String, 'Override the default output folder [.output]') do |i|
      args.output = i
    end

    opts.on('-z', '--timezone TIME_ZONE', String, 'Override the default timezone for folder naming [Australia/Melbourne]') do |i|
      args.timezone = TZInfo::Timezone.get(i)
    end

    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end
  end

  opt_parser.parse!(options)
  validate(args)
end

.validate(options) ⇒ Object

rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Layout/LineLength



56
57
58
59
60
61
62
63
# File 'lib/trello_freestyler/cli.rb', line 56

def self.validate(options)
  if options.key && options.token && options.board_id
    options
  else
    puts 'ERROR: One of the mandory arguments is missing. [--key, --token, --board_id]'
    exit 1
  end
end