localeapp 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -3
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +9 -0
  5. data/bin/localeapp +141 -119
  6. data/features/add.feature +15 -49
  7. data/features/bad_command.feature +4 -3
  8. data/features/env_file.feature +7 -0
  9. data/features/environment.feature +7 -0
  10. data/features/help.feature +3 -4
  11. data/features/install.feature +19 -33
  12. data/features/install/write_env_file.feature +26 -0
  13. data/features/mv.feature +9 -5
  14. data/features/options/api_key.feature +6 -0
  15. data/features/pull.feature +15 -27
  16. data/features/push.feature +15 -28
  17. data/features/rm.feature +10 -5
  18. data/features/step_definitions/cli_steps.rb +13 -10
  19. data/features/step_definitions/execution_steps.rb +3 -0
  20. data/features/step_definitions/filesystem_steps.rb +12 -0
  21. data/features/step_definitions/output_steps.rb +10 -0
  22. data/features/support/env.rb +2 -2
  23. data/features/update.feature +20 -29
  24. data/lib/localeapp.rb +7 -0
  25. data/lib/localeapp/cli/install.rb +28 -15
  26. data/lib/localeapp/cli/pull.rb +2 -1
  27. data/lib/localeapp/cli/push.rb +2 -1
  28. data/lib/localeapp/cli/remove.rb +2 -1
  29. data/lib/localeapp/cli/rename.rb +2 -1
  30. data/lib/localeapp/configuration.rb +1 -1
  31. data/lib/localeapp/poller.rb +4 -1
  32. data/lib/localeapp/sender.rb +1 -0
  33. data/lib/localeapp/version.rb +1 -1
  34. data/spec/localeapp/cli/install_spec.rb +103 -63
  35. data/spec/localeapp/cli/pull_spec.rb +1 -1
  36. data/spec/localeapp/cli/push_spec.rb +1 -1
  37. data/spec/localeapp/cli/rename_spec.rb +1 -1
  38. metadata +10 -6
  39. data/.autotest +0 -4
  40. data/.rvmrc +0 -1
  41. data/init.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 690435fd986bf2774e1e41678d33f661ac5666ea
4
- data.tar.gz: 34312483afc9c05268c324b6f4f870741a9216d2
3
+ metadata.gz: 778186a71665c8f24e361206ffa3b65ac2cee621
4
+ data.tar.gz: 60bfaf8940fd301c0854e2c1d41d4a2d4862cab8
5
5
  SHA512:
6
- metadata.gz: dd05673abf620abf78326d981e8565ba92c65639a2209b9c58af9ee5571897a5f857125f12afeefe21bd0e3a39a2f67e1e8e6acf304e64bdf4a8905c5a1b77e3
7
- data.tar.gz: fa285a2816b2e78254cb1abda09f9c3955447f34042429d1dbc5b3afa5ced32b18b84acbad55ce16fc34e3f10482199dde25b8e6489cdd53948de1451f5c14ab
6
+ metadata.gz: '06567599ed2fa7388bdcbd49b448d426ebfa581566128af299520eac8e56c1b4c993e0fa48ae6eb34eabd4ea87e7803d228e8c693381dab6809ad754c2a4ab0b'
7
+ data.tar.gz: 69ea7fb872f3f4524d448c31f968373a70e8db445b03328cb3392856d3e4e103363376cba9e51209c128adc9c907695cd0d033e17b385385121d16af1cea5c6f
data/.travis.yml CHANGED
@@ -3,12 +3,13 @@ dist: trusty
3
3
  before_install:
4
4
  - gem install bundler
5
5
  rvm:
6
- - 2.4.0
7
- - 2.3.3
8
- - 2.2.6
6
+ - 2.4.1
7
+ - 2.3.4
8
+ - 2.2.7
9
9
  - 2.1.10
10
10
  - jruby
11
11
  gemfile:
12
+ - Gemfile
12
13
  - gemfiles/i18n_0.4.gemfile
13
14
  - gemfiles/i18n_0.5.gemfile
14
15
  - gemfiles/i18n_0.6.gemfile
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # master
2
2
 
3
+ # Version 2.2.0
4
+
5
+ * Read API key from environment in generated config files, instead of
6
+ writing the API key directly in those files
7
+ * Fix handling of HTTP errors when querying API
8
+ * Stop checking project and app default locale at install
9
+
10
+ # Version 2.1.1
11
+
3
12
  * Support ruby 2.4
13
+
14
+ # Version 2.1.0
15
+
4
16
  * Drop ruby 1.9 and ruby 2.0 support
5
17
 
6
18
  # Version 2.0.0
data/README.md CHANGED
@@ -14,6 +14,15 @@ Though the i18n gem uses YAML as it's default file format it doesn't require ser
14
14
 
15
15
  ## Installation
16
16
 
17
+ Note that the API key is actually never written to configuration files
18
+ generated by the gem, but is expected to be set in the environment as
19
+ `LOCALEAPP_API_KEY`.
20
+
21
+ For convenience, the `install` command accepts a `-e` or
22
+ `--write-env-file` option that will append the API key to `.env` file,
23
+ so that you can use `foreman` or other tools supporting this
24
+ convention.
25
+
17
26
  ### Rails 3+
18
27
 
19
28
  Add the localeapp gem to your `Gemfile` and install it:
data/bin/localeapp CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'gli'
4
+
3
5
  require 'localeapp'
4
6
 
5
7
  # Don't connect to the net if we're running under cucumber for testing
@@ -11,157 +13,177 @@ if ENV['FAKE_WEB_DURING_CUCUMBER_RUN']
11
13
  end
12
14
  FakeWeb.allow_net_connect = false
13
15
  if fake_data_as_json = ENV['FAKE_WEB_FAKES']
14
- fakes = JSON.parse(fake_data_as_json)
16
+ fakes = YAML.load(fake_data_as_json)
15
17
  fakes.each do |fake|
16
18
  FakeWeb.register_uri fake['method'].to_sym, fake['uri'], { :body => fake['body'], :status => fake['status'] }.merge(fake['headers'])
17
19
  end
18
20
  end
19
21
  end
20
22
 
21
- require 'gli'
22
- gli2 = GLI::VERSION >= '2.0.0'
23
-
24
- if gli2
25
- include GLI::App
26
- else
27
- include GLI
28
- end
29
-
30
- pre do |global_options, command, options, args|
31
- global_options[:k] = if global_options[:k]
32
- global_options[:k]
33
- elsif ENV['LOCALEAPP_API_KEY']
34
- ENV['LOCALEAPP_API_KEY']
35
- elsif File.exist?('.env') && IO.read('.env') =~ /^LOCALEAPP_API_KEY=(\w+)$/
36
- $1
23
+ module LocaleappGLIWrapper
24
+ gli2 = GLI::VERSION >= '2.0.0'
25
+ if gli2
26
+ include GLI::App
37
27
  else
38
- nil
28
+ include GLI
39
29
  end
30
+ extend self
31
+
32
+ pre do |global_options, command, options, args|
33
+ global_options[:k] = if global_options[:k]
34
+ global_options[:k]
35
+ elsif ENV['LOCALEAPP_API_KEY']
36
+ ENV['LOCALEAPP_API_KEY']
37
+ elsif File.exist?('.env') && IO.read('.env') =~ /^LOCALEAPP_API_KEY=(\w+)$/
38
+ $1
39
+ else
40
+ nil
41
+ end
40
42
 
41
- if Localeapp.has_config_file? || !global_options[:k].nil?
42
- true
43
- else
44
- puts "Could not load config file and no key specified"
45
- exit 1
43
+ if Localeapp.has_config_file? || !global_options[:k].nil?
44
+ true
45
+ else
46
+ puts "Could not load config file and no key specified"
47
+ exit 1
48
+ end
46
49
  end
47
- end
48
50
 
49
- desc "API Key (for when there is no configuration file)"
50
- flag [:k, 'api-key']
51
-
52
- version Localeapp::VERSION
53
-
54
- desc "Creates new configuration files and confirms key works"
55
- skips_pre
56
- arg_name "<api_key>"
57
- command :install do |c|
58
- c.desc "install configuration files in .localeapp/"
59
- c.switch [:s, 'standalone']
60
-
61
- c.desc "create configuration when using localeapp via a heroku addon (PRE ALPHA)"
62
- c.switch [:h, 'heroku']
63
-
64
- c.desc "install a skeleton project suitable for Github (warning: README.md will be overwritten)"
65
- c.switch [:g, 'github']
66
-
67
- c.action do |global_options, options, args|
68
- key = args.first
69
- installer = Localeapp::CLI::Install.new
70
- installer.config_type = :standalone if options[:standalone]
71
- installer.config_type = :heroku if options[:heroku]
72
- installer.config_type = :github if options[:github]
73
- installer.config_type ||= :rails
74
- unless installer.execute(key)
75
- exit_now! "", 1
51
+ on_error do |ex|
52
+ case ex
53
+ when Localeapp::APIResponseError
54
+ $stderr.puts "ERROR: #{ex}"
55
+ exit 70
56
+ false
57
+ else
58
+ true
76
59
  end
77
60
  end
78
- end
79
61
 
80
- desc "Sends the key and content to localeapp.com"
81
- arg_name "<key> <locale:content> (<locale:content> ...)"
82
- command :add do |c|
83
- c.action do |global_options, options, args|
84
- key = args.shift
85
- if key.nil? || args.size.zero?
86
- exit_now! "localeapp add requires a key name and at least one translation", 1
87
- else
88
- Localeapp::CLI::Add.new(global_options).execute(key, *args)
62
+ desc "API Key (for when there is no configuration file)"
63
+ flag [:k, 'api-key']
64
+
65
+ version Localeapp::VERSION
66
+
67
+ desc "Creates new configuration files and confirms key works"
68
+ skips_pre
69
+ arg_name "<api_key>"
70
+ command :install do |c|
71
+ c.desc "install configuration files in .localeapp/"
72
+ c.switch [:s, 'standalone']
73
+
74
+ c.desc "create configuration when using localeapp via a heroku addon (PRE ALPHA)"
75
+ c.switch [:h, 'heroku']
76
+
77
+ c.desc "install a skeleton project suitable for Github " \
78
+ "(warning: will write to .gitignore and README.md"
79
+ c.switch [:g, 'github']
80
+
81
+ c.desc "write API key to `#{Localeapp.env_file_path}'"
82
+ c.switch [:e, "write-env-file"]
83
+
84
+ c.action do |global_options, options, args|
85
+ install_opts = {}
86
+ if options[:"write-env-file"]
87
+ install_opts[:write_env_file] = Localeapp.env_file_path
88
+ end
89
+ key = args.first
90
+ installer = Localeapp::CLI::Install.new
91
+ installer.config_type = :standalone if options[:standalone]
92
+ installer.config_type = :heroku if options[:heroku]
93
+ installer.config_type = :github if options[:github]
94
+ installer.config_type ||= :rails
95
+ unless installer.execute(key, install_opts)
96
+ exit_now! "", 1
97
+ end
89
98
  end
90
99
  end
91
- end
92
100
 
93
- desc "removes a key from the project"
94
- arg_name "<key>"
95
- command :rm do |c|
96
- c.action do |global_options, options, args|
97
- key = args.shift
98
- if key.nil?
99
- exit_now! "localeapp rm requires a key name", 1
100
- else
101
- Localeapp::CLI::Remove.new(global_options).execute(key, *args)
101
+ desc "Sends the key and content to localeapp.com"
102
+ arg_name "<key> <locale:content> (<locale:content> ...)"
103
+ command :add do |c|
104
+ c.action do |global_options, options, args|
105
+ key = args.shift
106
+ if key.nil? || args.size.zero?
107
+ exit_now! "localeapp add requires a key name and at least one translation", 1
108
+ else
109
+ Localeapp::CLI::Add.new(global_options).execute(key, *args)
110
+ end
102
111
  end
103
112
  end
104
- end
105
113
 
106
- desc "renames a key in the project"
107
- arg_name "<current key name> <new key name>"
108
- command :mv do |c|
109
- c.action do |global_options, options, args|
110
- current_name = args.shift
111
- new_name = args.shift
112
- if current_name.nil? || new_name.nil?
113
- exit_now! "localeapp mv requires a current key name and a new key name", 1
114
- else
115
- Localeapp::CLI::Rename.new(global_options).execute(current_name, new_name, *args)
114
+ desc "removes a key from the project"
115
+ arg_name "<key>"
116
+ command :rm do |c|
117
+ c.action do |global_options, options, args|
118
+ key = args.shift
119
+ if key.nil?
120
+ exit_now! "localeapp rm requires a key name", 1
121
+ else
122
+ Localeapp::CLI::Remove.new(global_options).execute(key, *args)
123
+ end
116
124
  end
117
125
  end
118
- end
119
126
 
120
- desc "Pulls all translations from localeapp.com"
121
- command :pull do |c|
122
- c.action do |global_options, options, args|
123
- Localeapp::CLI::Pull.new(global_options).execute
127
+ desc "renames a key in the project"
128
+ arg_name "<current key name> <new key name>"
129
+ command :mv do |c|
130
+ c.action do |global_options, options, args|
131
+ current_name = args.shift
132
+ new_name = args.shift
133
+ if current_name.nil? || new_name.nil?
134
+ exit_now! "localeapp mv requires a current key name and a new key name", 1
135
+ else
136
+ Localeapp::CLI::Rename.new(global_options).execute(current_name, new_name, *args)
137
+ end
138
+ end
124
139
  end
125
- end
126
140
 
127
- desc "Pushes a translation file or directory to localeapp.com"
128
- arg_name "<file>"
129
- command :push do |c|
130
- c.action do |global_options, options, args|
131
- if args.empty?
132
- exit_now! "localeapp push requires a file or directory to push", 1
133
- else
134
- path = args.first
135
- pusher = Localeapp::CLI::Push.new(global_options)
136
- pusher.execute(path)
141
+ desc "Pulls all translations from localeapp.com"
142
+ command :pull do |c|
143
+ c.action do |global_options, options, args|
144
+ Localeapp::CLI::Pull.new(global_options).execute
145
+ end
146
+ end
147
+
148
+ desc "Pushes a translation file or directory to localeapp.com"
149
+ arg_name "<file>"
150
+ command :push do |c|
151
+ c.action do |global_options, options, args|
152
+ if args.empty?
153
+ exit_now! "localeapp push requires a file or directory to push", 1
154
+ else
155
+ path = args.first
156
+ pusher = Localeapp::CLI::Push.new(global_options)
157
+ pusher.execute(path)
158
+ end
137
159
  end
138
160
  end
139
- end
140
161
 
141
- desc "Gets any changes since the last poll and updates the yml"
142
- command :update do |c|
143
- c.action do |global_options, options, args|
144
- Localeapp::CLI::Update.new(global_options).execute
162
+ desc "Gets any changes since the last poll and updates the yml"
163
+ command :update do |c|
164
+ c.action do |global_options, options, args|
165
+ Localeapp::CLI::Update.new(global_options).execute
166
+ end
145
167
  end
146
- end
147
168
 
148
- desc "Simple daemon (checks for new translations in the background)"
149
- command :daemon do |c|
150
- c.desc "Interval to wait between checks"
151
- c.arg_name 'interval'
152
- c.default_value 5
153
- c.flag [:i, :interval]
169
+ desc "Simple daemon (checks for new translations in the background)"
170
+ command :daemon do |c|
171
+ c.desc "Interval to wait between checks"
172
+ c.arg_name 'interval'
173
+ c.default_value 5
174
+ c.flag [:i, :interval]
154
175
 
155
- c.desc "run the daemon in the background"
156
- c.switch [:b, 'background']
176
+ c.desc "run the daemon in the background"
177
+ c.switch [:b, 'background']
157
178
 
158
- c.action do |global_options, options, args|
159
- Localeapp::CLI::Daemon.new(global_options).execute(options)
179
+ c.action do |global_options, options, args|
180
+ Localeapp::CLI::Daemon.new(global_options).execute(options)
181
+ end
160
182
  end
161
- end
162
183
 
163
- if gli2
164
- exit run(ARGV)
165
- else
166
- exit GLI.run(ARGV)
184
+ if gli2
185
+ exit run(ARGV)
186
+ else
187
+ exit GLI.run(ARGV)
188
+ end
167
189
  end
data/features/add.feature CHANGED
@@ -1,10 +1,9 @@
1
- Feature: Adding a translation from the command line
1
+ Feature: `add' command
2
2
 
3
- Scenario: Running add
4
- In order to add a key and translation content
3
+ Scenario: Adds the given translation
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
6
- And an initializer file
7
- When I run `localeapp add foo.baz en:"test en content" es:"test es content"`
5
+ And an initializer file
6
+ When I successfully run `localeapp add foo.baz en:"test en content" es:"test es content"`
8
7
  Then the output should contain:
9
8
  """
10
9
  Localeapp Add
@@ -13,60 +12,27 @@ Feature: Adding a translation from the command line
13
12
  Success!
14
13
  """
15
14
 
16
- Scenario: Running add with no arguments
17
- In order to add a key and translation content
15
+ Scenario: Reports an error when no translation is given
18
16
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
19
- And an initializer file
17
+ And an initializer file
20
18
  When I run `localeapp add`
21
- Then the output should contain:
19
+ Then the exit status must be 1
20
+ And the output should contain:
22
21
  """
23
22
  localeapp add requires a key name and at least one translation
24
23
  """
25
24
 
26
- Scenario: Running add with just a key name
27
- In order to add a key and translation content
25
+ Scenario: Reports an error when given a translation without description
28
26
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
29
- And an initializer file
27
+ And an initializer file
30
28
  When I run `localeapp add foo.bar`
31
29
  Then the output should contain:
32
30
  """
33
31
  localeapp add requires a key name and at least one translation
34
32
  """
35
33
 
36
- Scenario: Running add with no initializer file, passing the key on the command line
37
- In order to add a key and translation content
38
- Given I have a valid project on localeapp.com with api key "MYAPIKEY"
39
- When I run `localeapp -k MYAPIKEY add foo.baz en:"test en content"`
40
- Then the output should contain:
41
- """
42
- Localeapp Add
43
-
44
- Sending key: foo.baz
45
- Success!
46
- """
47
-
48
- Scenario: Running add with no initializer file, passing the key via an ENV variable
49
- In order to add a key and translation content
50
- Given I have a valid project on localeapp.com with api key "MYAPIKEY"
51
- And I have a LOCALEAPP_API_KEY env variable set to "MYAPIKEY"
52
- When I run `localeapp add foo.baz en:"test en content"`
53
- Then the output should contain:
54
- """
55
- Localeapp Add
56
-
57
- Sending key: foo.baz
58
- Success!
59
- """
60
-
61
- Scenario: Running add with no initializer file, passing the key via a .env file
62
- In order to add a key and translation content
63
- Given I have a valid project on localeapp.com with api key "MYAPIKEY"
64
- And I have a .env file containing the api key "MYAPIKEY"
65
- When I run `localeapp add foo.baz en:"test en content"`
66
- Then the output should contain:
67
- """
68
- Localeapp Add
69
-
70
- Sending key: foo.baz
71
- Success!
72
- """
34
+ Scenario: Reports an error when the given API key is incorrect
35
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
36
+ When I run `localeapp -k MYAPIKEY add foo en:bar`
37
+ Then the exit status must be 70
38
+ And the output must match /error.+404/i