Skip to content

Commit efd89f9

Browse files
authored
Merge pull request #50 from yumaoka/rfe-49-cli-updlang
Added update-bundle command to gp-cli
2 parents 9ea4823 + a822a85 commit efd89f9

4 files changed

Lines changed: 136 additions & 2 deletions

File tree

gp-cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ are the translation target languages.
139139
java -jar gp-cli.jar create -b MyNewBundle -l en,fr,de -j mycreds.json
140140
```
141141

142+
#### update (update-bundle)
143+
144+
Updates an existing bundle's configuration.
145+
146+
The following example sets French (fr), German (de) and Italian (it)
147+
as target languages and the translation instruction note "These are
148+
Java MessageFormat ...".
149+
```
150+
java -jar gp-cli.jar update -b MyBundle -l fr,de,it -n "These are Java MessageFormat pattern strings"
151+
```
152+
142153
#### import
143154

144155
Imports resource data to a bundle. This command takes an input language.

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/GPCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright IBM Corp. 2015,2016
2+
* Copyright IBM Corp. 2015,2016,2017
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@ public static void main(String[] args) {
4646
jc.addCommand("list-bundle", new ListBundlesCmd(), "list");
4747
jc.addCommand("show-bundle", new ShowBundleCmd(), "show");
4848
jc.addCommand("create-bundle", new CreateBundleCmd(), "create");
49+
jc.addCommand("update-bundle", new UpdateBundleCmd(), "update");
4950
jc.addCommand("delete-bundle", new DeleteBundleCmd(), "delete");
5051
jc.addCommand("copy-bundle", new CopyBundleCmd(), "copy");
5152
jc.addCommand("copy-all-bundles", new CopyAllBundlesCmd());

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/ShowBundleCmd.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright IBM Corp. 2015,2016
2+
* Copyright IBM Corp. 2015,2016,2017
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package com.ibm.g11n.pipeline.tools.cli;
1717

1818
import java.util.Date;
19+
import java.util.List;
1920
import java.util.Set;
2021

2122
import com.beust.jcommander.Parameters;
@@ -36,6 +37,7 @@ final class ShowBundleCmd extends BundleCmd {
3637
static class BundleDataJson {
3738
String sourceLanguage;
3839
Set<String> targetLanguages;
40+
List<String> notes;
3941
boolean readOnly;
4042
String updatedBy;
4143
Date updatedAt;
@@ -50,6 +52,7 @@ protected void _execute() {
5052

5153
outJson.sourceLanguage = bundleData.getSourceLanguage();
5254
outJson.targetLanguages = bundleData.getTargetLanguages();
55+
outJson.notes = bundleData.getNotes();
5356
outJson.readOnly = bundleData.isReadOnly();
5457
outJson.updatedBy = bundleData.getUpdatedBy();
5558
outJson.updatedAt = bundleData.getUpdatedAt();
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright IBM Corp. 2017
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ibm.g11n.pipeline.tools.cli;
17+
18+
import java.util.Collections;
19+
import java.util.HashSet;
20+
import java.util.List;
21+
import java.util.Set;
22+
23+
import com.beust.jcommander.Parameter;
24+
import com.beust.jcommander.Parameters;
25+
import com.ibm.g11n.pipeline.client.BundleDataChangeSet;
26+
import com.ibm.g11n.pipeline.client.ServiceException;
27+
28+
/**
29+
* Updates an existing translation bundle.
30+
*
31+
* @author Yoshito Umaoka
32+
*/
33+
@Parameters(commandDescription = "Updates an existing translation bundle.")
34+
public class UpdateBundleCmd extends BundleCmd {
35+
36+
@Parameter(
37+
names = {"-l", "--languages"},
38+
description = "List of bundle's target language ID(s) separted by comma. "
39+
+ "Empty list \"\" will remove all existing target languages.")
40+
private String languageIdsListStr;
41+
42+
@Parameter(
43+
names = {"-n", "--note"},
44+
description = "Translation instruction note. "
45+
+ "Empty note \"\" will remove existing instruction note.")
46+
private String note;
47+
48+
@Parameter(
49+
names = {"-r", "--readOnly"},
50+
description = "true to set the bundle read only.")
51+
private String readOnlyStr;
52+
53+
@Override
54+
protected void _execute() {
55+
Set<String> trgLangs = null;
56+
if (languageIdsListStr != null) {
57+
String[] langs = languageIdsListStr.split(",");
58+
trgLangs = new HashSet<>(langs.length);
59+
for (String lang : langs) {
60+
if (lang.isEmpty()) {
61+
continue;
62+
}
63+
trgLangs.add(lang);
64+
}
65+
}
66+
67+
List<String> notes = null;
68+
if (note != null) {
69+
if (note.isEmpty()) {
70+
// Empty note will delete the existing note
71+
notes = Collections.emptyList();
72+
} else {
73+
notes = Collections.singletonList(note);
74+
}
75+
}
76+
77+
Boolean readOnly = null;
78+
if (readOnlyStr != null) {
79+
if (readOnlyStr.equalsIgnoreCase("true")) {
80+
readOnly = Boolean.TRUE;
81+
} else if (readOnlyStr.equalsIgnoreCase("false")) {
82+
readOnly = Boolean.FALSE;
83+
} else {
84+
System.out.println("Bad -r (--readOnly) argument value: " + readOnlyStr
85+
+ ". The command argument will be ignored.");
86+
}
87+
}
88+
89+
if (languageIdsListStr == null && notes == null && readOnlyStr == null) {
90+
System.out.println("Nothing to update.");
91+
return;
92+
}
93+
94+
BundleDataChangeSet changes = new BundleDataChangeSet();
95+
changes
96+
.setTargetLanguages(trgLangs)
97+
.setNotes(notes)
98+
.setReadOnly(readOnly);
99+
100+
try {
101+
getClient().updateBundle(bundleId, changes);
102+
} catch (ServiceException e) {
103+
throw new RuntimeException(e);
104+
}
105+
106+
System.out.println("Bundle " + bundleId + " was successfully updated.");
107+
if (trgLangs != null) {
108+
String newTrgLangs = trgLangs.isEmpty() ? "<removed>" : trgLangs.toString();
109+
System.out.println("- Target languages: " + newTrgLangs);
110+
}
111+
if (notes != null) {
112+
String newNote = notes.isEmpty() ? "<removed>" : notes.get(0);
113+
System.out.println("- Translation instruction note: " + newNote);
114+
}
115+
if (readOnly != null) {
116+
System.out.println("- Read only: " + readOnly);
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)