49ffb51b60dc1cfdf60a42e72a336ffd791027ae
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / Help.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.cmd;
23
24 import java.util.List;
25
26 import org.onap.aaf.cadi.CadiException;
27 import org.onap.aaf.cadi.LocatorException;
28 import org.onap.aaf.misc.env.APIException;
29
30 public class Help extends Cmd {
31     private List<Cmd> cmds;
32
33     public Help(AAFcli aafcli, List<Cmd> cmds) {
34         super(aafcli, "help", 
35             new Param("-d (more details)", false),
36             new Param("command",false));
37         this.cmds = cmds;
38     }
39
40     @Override
41     public int _exec( int idxValue, final String ... args) throws CadiException, APIException, LocatorException {
42             int idx = idxValue;
43         boolean first = true;
44         StringBuilder sb = new StringBuilder("AAF Command Line Tool");
45         StringBuilder details;
46         multiChar(sb, 21, '-',0);
47         sb.append("\n  SingleLine Commands");
48         multiChar(sb, 21, '-',2);
49         sb.append("\n    force   - add to regular commands to override depency checks");
50         sb.append("\n    details - add to role list or perm list commands for rich format");
51         multiChar(sb, 48, '-',2);
52         // if details !=null, then extra details are written to it.
53         details = aafcli.isDetailed()?new StringBuilder():null;
54
55         String comp = args.length>idx?args[idx++]:null;
56         if ("help".equalsIgnoreCase(comp)) {
57             build(sb,null);
58             detailedHelp(4, sb);
59             sb.append('\n');
60         } else {
61             for (Cmd c : cmds) {
62                 if (!(c instanceof DeprecatedCMD)) {
63                     if (comp!=null) {
64                         if (comp.equals(c.getName())) {
65                             multiChar(sb,2,' ',0);
66                             c.build(sb,details);
67                         }
68                     } else {
69                         if (first) {
70                             first=false;
71                         } else {
72                             multiChar(sb,80,'-',2);
73                         }
74                         multiChar(sb,2,' ',0);
75                         c.build(sb,details);
76                         if (details!=null) {
77                             c.detailedHelp(4, sb);
78                         }
79                     }
80                 }
81             }
82         }
83         pw().println(sb.toString());
84         return 200 /*HttpStatus.OK_200*/;
85     }
86     
87     @Override
88     public void detailedHelp(int indentValue, StringBuilder sb) {
89             int indent = indentValue;
90         detailLine(sb,indent,"To print main help, enter \"aafcli\" or \"aafcli --help \"");
91         detailLine(sb,indent,"To print narrow the help content, enter sub-entries after aafcli,");
92         detailLine(sb,indent+2,"i.e. \"aafcli perm\"");
93         detailLine(sb,indent,"To see version of AAF CLI, enter \"aafcli --version \"");
94         sb.append('\n');
95         detailLine(sb,indent,"State Commands: change variables or credentials between calls.");
96         indent+=4;
97         detailLine(sb,indent,"set <tag>=<value>   - Set any System Property to a new value");
98         detailLine(sb,indent,"as <id:password>    - Change Credentials.  Password may be encrypted");
99         detailLine(sb,indent,"expect <int> [int]* - In test mode, check for proper HTTP Status Codes");
100         detailLine(sb,indent,"sleep <int>         - Wait for <int> seconds");
101         detailLine(sb,indent,"force               - force deletions that have relationships");
102         detailLine(sb,indent,"details               - cause list commands (role, perm) to print rich format");
103         detailLine(sb,indent,"                       - In GUI CmdLine, use HourGlass option (top right)");
104         sb.append('\n');
105         detailLine(sb,indent-4,"CmdLine Arguments: change behavior of the aafcli program");
106         detailLine(sb,indent,"-i - Read commands from Shell Standard Input");
107         detailLine(sb,indent,"-f - Read commands from a file");
108         detailLine(sb,indent,"-r - Clear Command Line SSO credential");
109         detailLine(sb,indent,"-a - In test mode, do not stop execution on unexpected error");
110         detailLine(sb,indent,"-t - Test Mode will not print variable fields that could break tc runs");
111         detailLine(sb,indent+6,"such as expiration dates of a credential");
112         detailLine(sb,indent,"-s - Request specific Start Date (not immediately)");
113         detailLine(sb,indent+6,"Format YYYY-MM-DD.  Can also be set with \"set " + Cmd.STARTDATE + "=<value>\"");
114         detailLine(sb,indent,"-e - Set Expiration/End Date, where commands support");
115         detailLine(sb,indent+6,"Format YYYY-MM-DD.  Can also be set with \"set " + Cmd.ENDDATE + "=<value>\"");
116     }
117 }