Class: Rosette::Client::Commands::PullCommandArgs

Inherits:
Struct
  • Object
show all
Defined in:
lib/rosette/client/commands/pull_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#file_patternObject

Returns the value of attribute file_pattern

Returns:

  • (Object)

    the current value of file_pattern



12
13
14
# File 'lib/rosette/client/commands/pull_command.rb', line 12

def file_pattern
  @file_pattern
end

#pathsObject

Returns the value of attribute paths

Returns:

  • (Object)

    the current value of paths



12
13
14
# File 'lib/rosette/client/commands/pull_command.rb', line 12

def paths
  @paths
end

#refObject

Returns the value of attribute ref

Returns:

  • (Object)

    the current value of ref



12
13
14
# File 'lib/rosette/client/commands/pull_command.rb', line 12

def ref
  @ref
end

#serializerObject

Returns the value of attribute serializer

Returns:

  • (Object)

    the current value of serializer



12
13
14
# File 'lib/rosette/client/commands/pull_command.rb', line 12

def serializer
  @serializer
end

Class Method Details

.from_argv(argv, repo, terminal) ⇒ Object



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/rosette/client/commands/pull_command.rb', line 13

def self.from_argv(argv, repo, terminal)
  options = { paths: '' }

  parser = OptionParser.new do |opts|
    desc = "File pattern to use. Can contain these placeholders:\n" +
      "* %{locale.code}: The full locale code, eg. pt-BR\n" +
      "* %{locale.territory}: The locale's territory part, eg. 'BR'" +
      "* %{locale.language}: The locale's language part, eg. 'pt'"

    opts.on('-f pattern', '--file-pattern pattern', desc) do |pattern|
      pattern.strip!
      options[:file_pattern] = pattern.empty? ? nil : pattern
    end

    desc = 'The serializer to use. Translations will be requested in ' +
      'this format.'

    opts.on('-s serializer', '--serializer serializer', desc) do |serializer|
      serializer.strip!
      options[:serializer] = serializer.empty? ? nil : serializer
    end

    desc = 'The paths to use to restrict the export to only phrases ' +
      'found at those paths. Should be pipe-separated.'

    opts.on('-p paths', '--paths paths', desc) do |path|
      options[:paths] = path.strip
    end
  end

  parser.parse(argv)
  options[:ref] = repo.rev_parse(argv[0] || repo.get_head)
  validate_options!(options, terminal)

  new(
    options[:ref],
    options[:file_pattern],
    options[:serializer],
    options[:paths]
  )
end

.validate_options!(options, terminal) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rosette/client/commands/pull_command.rb', line 55

def self.validate_options!(options, terminal)
  unless options.include?(:file_pattern)
    terminal.say('Please supply a file pattern via the -f option')
    exit 1
  end

  unless options.include?(:serializer)
    terminal.say('Please supply a serializer via the -s option')
    exit 1
  end
end