View Javadoc
1   package org.codehaus.plexus.tools.cli;
2   
3   /*
4    * Copyright 2006 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.PlexusContainer;
20  import org.codehaus.plexus.util.FileUtils;
21  import org.apache.commons.cli.Options;
22  import org.apache.commons.cli.CommandLine;
23  import org.apache.commons.cli.OptionBuilder;
24  
25  import java.io.File;
26  
27  /**
28   * @author Jason van Zyl
29   */
30  public class TestCli
31      extends AbstractCli
32  {
33      public static void main( String[] args )
34          throws Exception
35      {
36          new TestCli().execute( args );
37      }
38  
39      public Options buildCliOptions( Options options )
40      {
41          options.addOption(
42              OptionBuilder.withLongOpt( "name" ).withDescription( "Display name." ).hasArg().create( 'n' ) );
43  
44          return options;
45      }
46  
47      public void invokePlexusComponent( CommandLine cli,
48                                         PlexusContainer container )
49          throws Exception
50      {
51          if ( cli.hasOption( 'n' ) )
52          {
53              String directory = cli.getOptionValue( 'n' );
54  
55              FileUtils.mkdir( new File( directory, "target" ).getAbsolutePath() );
56  
57              FileUtils.fileWrite( new File( directory, "target/cli.txt").getAbsolutePath() , "NAME_OPTION_INVOKED" );
58          }
59      }
60  }