1 /*
2  * Concat.java
3  *
4  * jcmdline Rel. @VERSION@ $Id: Concat.java,v 1.3 2009/08/06 14:31:35 lglawrence Exp $
5  *
6  * Classes:
7  *   public   Concat
8  *
9  * ***** BEGIN LICENSE BLOCK *****
10  * Version: MPL 1.1
11  *
12  * The contents of this file are subject to the Mozilla Public License Version
13  * 1.1 (the "License"); you may not use this file except in compliance with
14  * the License. You may obtain a copy of the License at
15  * http://www.mozilla.org/MPL/
16  *
17  * Software distributed under the License is distributed on an "AS IS" basis,
18  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
19  * for the specific language governing rights and limitations under the
20  * License.
21  *
22  * The Original Code is the Java jcmdline (command line management) package.
23  *
24  * The Initial Developer of the Original Code is Lynne Lawrence.
25  *
26  * Portions created by the Initial Developer are Copyright (C) 2002
27  * the Initial Developer. All Rights Reserved.
28  *
29  * Contributor(s):  Lynne Lawrence <lgl@visuallink.com>
30  *
31  * ***** END LICENSE BLOCK *****
32  */
33 
34 package jcmdline;
35 
36 import java.io.File;
37 
38 /**
39  * "junk class" to test CmdLineParser with paramters used in CmdLineParser
40  * javadoc.
41  *
42  * @author Lynne Lawrence
43  * @version jcmdline Rel. @VERSION@ $Id: Concat.java,v 1.2 2002/12/07 14:30:49
44  *          lglawrence Exp $
45  */
46 public class Concat {
47 
48 	/**
49 	 * this command's help text
50 	 */
51 	static String helpMsg = "Concat is used to concatenate the files specified by <filename> "
52 			+ "together.  By default, the concatenated files are written to "
53 			+ "stdout.\n\nIf the '-out' option is specified, the "
54 			+ "concatenated files "
55 			+ "will be written to the specified file instead of stdout.\n\nThe "
56 			+ "'-delete' option specifies that the original files be deleted";
57 
58 	/**
59 	 * an optional 'outfile' command line option
60 	 */
61 	static FileParam outfile = new FileParam("out",
62 			"a file to receive the concatenated files (default is stdout)");
63 
64 	/**
65 	 * an optional 'delete' command line option
66 	 */
67 	static BooleanParam delete = new BooleanParam("delete",
68 			"specifies that all of the original files are to be deleted");
69 
70 	/**
71 	 * required, multivalued, 'filename' command line parameter
72 	 */
73 	static FileParam infiles = new FileParam("filename",
74 			"files to be concatenated", FileParam.IS_FILE
75 					& FileParam.IS_READABLE, FileParam.REQUIRED,
76 			FileParam.MULTI_VALUED);
77 
78 	/**
79 	 * main - doesn't actually do anything other than process command line
80 	 * parameters and print them out.
81 	 *
82 	 * @param args
83 	 *            command line arguments
84 	 */
main(String[] args)85 	public static void main(String[] args) {
86 		outfile.setOptionLabel("outfile");
87 		CmdLineHandler clp = new DefaultCmdLineHandler(
88 				// CmdLineParser clp = new CmdLineParser(
89 				"Concat", "concatenates the specified files",
90 				// "V2.3", helpMsg,
91 				new Parameter[] { outfile, delete },
92 				new Parameter[] { infiles });
93 		clp.parse(args);
94 
95 		System.out.println("Outfile:");
96 		if (outfile.isSet()) {
97 			System.out.println("   " + outfile.getValue().getPath());
98 		} else {
99 			System.out.println("   stdout");
100 		}
101 		System.out.println("Infiles:");
102 		for (File f : infiles.getValues()) {
103 			System.out.println("   " + f.getPath());
104 		}
105 		if (delete.isTrue()) {
106 			System.out.println("Deleting original files");
107 		} else {
108 			System.out.println("Not deleting original files");
109 		}
110 	}
111 }
112