Review Board 1.7.22


SQOOP-1162: Sqoop2: 'show option' should have help entry showing that 'all' arg can be used

Review Request #13273 - Created Aug. 5, 2013 and updated

Mengwei Ding
SQOOP-1162
Reviewers
Sqoop
abe, hshreedharan, jarcec
sqoop-sqoop2
commit 894e2fe8b01cd1d12f4f8e9377a60707a22faf04
Author: Mengwei Ding <mengwei.ding@gmail.com>
Date:   Mon Aug 5 10:47:29 2013 -0700

    SQOOP-1162: Sqoop2: 'show option' should have help entry showing that 'all' arg can be used

:100644 100644 672fa85... 0520bfa... M	shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
:100644 100644 5e3c3ff... 6c8cb0f... M	shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
:100644 100644 475f41c... f7d02e5... M	shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
:100644 100644 df9457d... fd268b0... M	shell/src/main/resources/shell-resource.properties

 
shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
Revision 672fa85 New Change
[20] 14 lines
[+20]
15
 * See the License for the specific language governing permissions and
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
package org.apache.sqoop.shell;
18
package org.apache.sqoop.shell;
19

    
   
19

   

    
   
20
import java.util.ArrayList;

    
   
21
import java.util.Collections;

    
   
22
import java.util.Comparator;
20
import java.util.List;
23
import java.util.List;
21

    
   
24

   

    
   
25
import org.apache.commons.cli.Option;
22
import org.apache.sqoop.shell.core.Constants;
26
import org.apache.sqoop.shell.core.Constants;
23
import org.codehaus.groovy.tools.shell.Shell;
27
import org.codehaus.groovy.tools.shell.Shell;
24

    
   
28

   
25
import static org.apache.sqoop.shell.ShellEnvironment.*;
29
import static org.apache.sqoop.shell.ShellEnvironment.*;
26

    
   
30

   
[+20] [20] 74 lines
[+20] [+] public Object executeCommand(List args) {
101
    } else {
105
    } else {
102
      printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
106
      printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
103
      return null;
107
      return null;
104
    }
108
    }
105
  }
109
  }

    
   
110

   

    
   
111
  @Override

    
   
112
  public String getHelp() {

    
   
113
    StringBuilder help = new StringBuilder();

    
   
114

   

    
   
115
    help.append(super.getHelp());

    
   
116
    help.append("\n\n");

    
   
117

   

    
   
118
    if (serverFunction == null) {

    
   
119
      serverFunction = new ShowServerFunction();

    
   
120
    }

    
   
121
    help.append("show server \n");

    
   
122
    help.append(getFunctionHelp(serverFunction));

    
   
123

   

    
   
124
    if (versionFunction == null) {

    
   
125
      versionFunction = new ShowVersionFunction();

    
   
126
    }

    
   
127
    help.append("show version \n");

    
   
128
    help.append(getFunctionHelp(versionFunction));

    
   
129

   

    
   
130
    if (connectorFunction == null) {

    
   
131
      connectorFunction = new ShowConnectorFunction();

    
   
132
    }

    
   
133
    help.append("show connector \n");

    
   
134
    help.append(getFunctionHelp(connectorFunction));

    
   
135

   

    
   
136
    if (frameworkFunction == null) {

    
   
137
      frameworkFunction = new ShowFrameworkFunction();

    
   
138
    }

    
   
139
    help.append("show framework \n");

    
   
140
    help.append(getFunctionHelp(frameworkFunction));

    
   
141

   

    
   
142
    if (connectionFunction == null) {

    
   
143
      connectionFunction = new ShowConnectionFunction();

    
   
144
    }

    
   
145
    help.append("show connection \n");

    
   
146
    help.append(getFunctionHelp(connectionFunction));

    
   
147

   

    
   
148
    if (jobFunction == null) {

    
   
149
      jobFunction = new ShowJobFunction();

    
   
150
    }

    
   
151
    help.append("show job \n");

    
   
152
    help.append(getFunctionHelp(jobFunction));

    
   
153

   

    
   
154
    if (submissionFunction == null) {

    
   
155
      submissionFunction = new ShowSubmissionFunction();

    
   
156
    }

    
   
157
    help.append("show submission \n");

    
   
158
    help.append(getFunctionHelp(submissionFunction));

    
   
159

   

    
   
160
    if (optionFunction == null) {

    
   
161
      optionFunction = new ShowOptionFunction();

    
   
162
    }

    
   
163
    help.append("show option \n");

    
   
164
    help.append(getFunctionHelp(optionFunction));

    
   
165

   

    
   
166
    return help.toString();

    
   
167
  }

    
   
168

   

    
   
169
  private String getFunctionHelp(SqoopFunction function) {

    
   
170
    StringBuilder builder = new StringBuilder();

    
   
171

   

    
   
172
    ArrayList<Option> args = new ArrayList<Option>();

    
   
173
    args.addAll(function.getOptions());

    
   
174

   

    
   
175
    // sort all args based on their names

    
   
176
    Collections.sort(args, new Comparator<Option>() {

    
   
177

   

    
   
178
      @Override

    
   
179
      public int compare(Option o1, Option o2) {

    
   
180
        return o1.getLongOpt().compareTo(o2.getLongOpt());

    
   
181
      }

    
   
182

   

    
   
183
    });

    
   
184

   

    
   
185
    for (Option arg : args) {

    
   
186
      builder.append("\t-");

    
   
187
      builder.append(arg.getOpt());

    
   
188
      builder.append(", --");

    
   
189
      builder.append(arg.getLongOpt());

    
   
190
      builder.append("\n\t\t");

    
   
191
      builder.append(arg.getDescription());

    
   
192
      builder.append("\n");

    
   
193
    }

    
   
194
    builder.append("\n");

    
   
195

   

    
   
196
    return builder.toString();

    
   
197
  }
106
}
198
}
shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
Revision 5e3c3ff New Change
 
shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
Revision 475f41c New Change
 
shell/src/main/resources/shell-resource.properties
Revision df9457d New Change
 
  1. shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java: Loading...
  2. shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java: Loading...
  3. shell/src/main/java/org/apache/sqoop/shell/core/Constants.java: Loading...
  4. shell/src/main/resources/shell-resource.properties: Loading...