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