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