phrase 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phrase/tool/commands/push.rb +32 -29
- data/lib/phrase/version.rb +1 -1
- metadata +1 -1
@@ -9,7 +9,7 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
9
9
|
super(options, args)
|
10
10
|
require_auth_token!
|
11
11
|
|
12
|
-
@
|
12
|
+
@file_names = @args[1..-1]
|
13
13
|
@locale = @options.get(:locale)
|
14
14
|
@tags = @options.get(:tags)
|
15
15
|
@recursive = @options.get(:recursive)
|
@@ -21,7 +21,8 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
21
21
|
exit_command
|
22
22
|
end
|
23
23
|
|
24
|
-
files = choose_files_to_upload
|
24
|
+
files = choose_files_to_upload(@file_names, @recursive)
|
25
|
+
|
25
26
|
if files.empty?
|
26
27
|
print_message "Could not find any files to upload".light_red
|
27
28
|
exit_command
|
@@ -31,10 +32,12 @@ class Phrase::Tool::Commands::Push < Phrase::Tool::Commands::Base
|
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
34
|
-
def choose_files_to_upload
|
35
|
-
|
35
|
+
def choose_files_to_upload(file_names, recursive=false)
|
36
|
+
files = []
|
37
|
+
|
38
|
+
if file_names.empty?
|
36
39
|
if rails_default_locale_folder_available?
|
37
|
-
|
40
|
+
file_names = [RAILS_DEFAULT_FOLDER]
|
38
41
|
print_message "No file or directory specified, using #{RAILS_DEFAULT_FOLDER}"
|
39
42
|
else
|
40
43
|
print_error "Need either a file or directory:"
|
@@ -43,37 +46,31 @@ private
|
|
43
46
|
exit_command
|
44
47
|
end
|
45
48
|
end
|
49
|
+
|
50
|
+
file_names.each do |file_name|
|
51
|
+
if File.directory?(file_name)
|
52
|
+
pattern = recursive ? "#{File.expand_path(file_name)}/**/*" : "#{File.expand_path(file_name)}/**"
|
53
|
+
files += Dir.glob(pattern)
|
54
|
+
else
|
55
|
+
files << file_name
|
56
|
+
end
|
57
|
+
end
|
46
58
|
|
47
|
-
|
48
|
-
print_error "The file #{@file_name} could not be found."
|
49
|
-
exit_command
|
50
|
-
end
|
51
|
-
|
52
|
-
if File.directory?(@file_name)
|
53
|
-
pattern = @recursive ? "#{File.expand_path(@file_name)}/**/*" : "#{File.expand_path(@file_name)}/**"
|
54
|
-
files = Dir.glob(pattern)
|
55
|
-
else
|
56
|
-
files = [@file_name]
|
57
|
-
end
|
59
|
+
files
|
58
60
|
end
|
59
61
|
|
60
62
|
def upload_files(files)
|
61
|
-
files.each
|
63
|
+
files.each do |file|
|
64
|
+
if file_exists?(file)
|
65
|
+
upload_file(file)
|
66
|
+
else
|
67
|
+
print_error "The file #{file} could not be found."
|
68
|
+
end
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
def upload_file(file)
|
65
|
-
|
66
|
-
|
67
|
-
if File.directory?(file)
|
68
|
-
valid = false
|
69
|
-
else
|
70
|
-
unless file_valid?(file)
|
71
|
-
valid = false
|
72
|
-
print_error "Notice: Could not upload #{file} (type not supported)"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
if valid
|
73
|
+
if file_valid?(file)
|
77
74
|
begin
|
78
75
|
tagged = " (tagged: #{@tags.join(", ")})" if @tags.size > 0
|
79
76
|
print_message "Uploading #{file}#{tagged}..."
|
@@ -89,6 +86,8 @@ private
|
|
89
86
|
print_error "Failed"
|
90
87
|
print_server_error(e.message)
|
91
88
|
end
|
89
|
+
else
|
90
|
+
print_error "Notice: Could not upload #{file} (type not supported)"
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
@@ -114,6 +113,10 @@ private
|
|
114
113
|
extension = filepath.split('.').last
|
115
114
|
ALLOWED_FILE_TYPES.include?(extension)
|
116
115
|
end
|
116
|
+
|
117
|
+
def file_exists?(file)
|
118
|
+
File.exist?(file)
|
119
|
+
end
|
117
120
|
|
118
121
|
def valid_tags_are_given?(tags)
|
119
122
|
tags.all? { |tag| Phrase::Tool::TagValidator.valid?(tag) }
|
data/lib/phrase/version.rb
CHANGED