99af925a6a8d9566b104183bf7dddcb777edb6af
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / HelpInfo.java
1 /** @file
2 File is HelpInfo class which is used to output the usage info.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13
14 package org.tianocore.context;
15
16 import java.util.LinkedList;
17
18 public class HelpInfo {
19
20
21 /**
22 * output the tools usage guide
23 * @param no input parameter
24 * @return no return value
25 **/
26 public static void outputUsageInfo() {
27 System.out.printf("\n%s", UsageInfoString);
28 System.out.printf("\n%s", DetailOfOptionString);
29
30 for (int i = 0; i < 6; i++) {
31 outputSubUsageInfo(UsageString[i], UsageStringInfo[i]);
32 }
33
34 System.out.printf("\n%s", ExampleString);
35 }
36
37 /**
38 * output the usage info which bases on cmd option
39 * @param String str1 : the cmd option
40 * String str2 : the detail of cmd option
41 * @return no return value
42 **/
43 private static void outputSubUsageInfo(String str1, String str2) {
44
45 splitString(str2);
46 System.out.printf("\n%4s %-30s %s", "", str1, List.get(0));
47 for (int i=1; i<List.size(); i++){
48 System.out.printf("\n%4s %-30s %s", "", "", List.get(i));
49 }
50 List.clear();
51 }
52
53 /**
54 * according to the output width, split the detail info
55 * @param String str :the detail info
56 * @return no return value
57 **/
58 private static void splitString(String str) {
59 int strlength = str.length();
60 if (strlength > MaxSrtingLength) {
61 String[] tokens = str.split("[ ]", 0);
62 String tempstr = null;
63 int templength = 0;
64 int start = 0;
65 int end = 0;
66 for (int i = 0; i < tokens.length; i++) {
67 if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) {
68 end = templength;
69 } else {
70 tempstr = str.substring(start, end);
71 List.add(tempstr);
72 start = end;
73 i = i - 1;
74 }
75 }
76 tempstr = str.substring(start, end - 1);
77 List.add(tempstr);
78 } else {
79 List.add(str);
80 }
81 }
82
83
84 private static LinkedList<String> List = new LinkedList<String>();
85
86 private static final int MaxSrtingLength = 40;
87
88 private static final String UsageInfoString = "Usage: ContextTool [-option1] [args] [-option2] [args] ...";
89
90 private static final String DetailOfOptionString = "Where options include:";
91
92 private static final String ExampleString = "Example: ContextTool -a IA32 IA64 EBC -c Tools/Conf/tools_def.txt -t DEBUG";
93
94 private static final String HString = "-h";
95
96 private static final String HStringInfo = "print this help message";
97
98 private static final String AString = "-a <list of Arch>";
99
100 private static final String AStringInfo = "what kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values.";
101
102 private static final String CString = "-c <tool_definition_file.txt>";
103
104 private static final String CStringInfo = "Assign a txt file, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/. If no file is specified, the default filename is \"tools_def.txt\"";
105
106 private static final String NString = "-n <list of TagNames>";
107
108 private static final String NStringInfo = "Specify the TagName, such as GCC, MSFT, which are defined in the \"tool_definition_file.txt\"";
109
110 private static final String PString = "-p <*.fpd>";
111
112 private static final String PStringInfo = "Specify the WORKSPACE relative Path and Filename of platform FPD file that will be used for the build.";
113
114 private static final String TString = "-t <list of Build Targets>";
115
116 private static final String TStringInfo = "What kind of the version is the binary target, such as DEBUG, RELEASE. Multiple values can be specified on a single line, using space to separate the values.";
117
118 private static final String[] UsageString = { HString, AString, CString,
119 NString, PString, TString };
120
121 private static final String[] UsageStringInfo = { HStringInfo, AStringInfo,
122 CStringInfo, NStringInfo, PStringInfo, TStringInfo };
123 }