Skip to content

pkraeutli/console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Astina Console

Java port of the famous Symfony Console.

Note: This is just an experiment. For something production ready, check out CRaSH.

Done

  • Defining commands
  • Running commands
  • Basic interactions
  • Text output

Todo

  • Array arguments
  • Interaction validation
  • Choice interactions
  • JSON, XML, ... output
  • Events

Usage

Create your command classes by extending the ch.astina.console.command.Command base class:

import ch.astina.console.*;

public class FileListCommand extends Command
{
    @Override
    protected void configure()
    {
        this
            .setName("ls")
            .setDescription("Displays files in the given directory")
            .addArgument("dir", InputArgument.REQUIRED, "Directory name")
            .addOption("long", "l", InputOption.VALUE_NONE, "List in long format.")
            .setHelp("Some help text ...")
        ;
    }

    @Override
    protected int execute(Input input, Output output)
    {
        // todo implement

        return 0;
    }
}

Prepare the console:

import ch.astina.console.Application;

public class Console
{
    public static void main(String[] args)
    {
        Application app = new Application();
        app.add(new FileListCommand());
        app.add((new Command("foo")).setExecutor(new CommandExecutor()
        {
            @Override
            public int execute(Input input, Output output)
            {
                output.writeln("<info>Bar!</info>");

                return 0;
            }
        }));

        int exitCode = app.run(args);

        System.exit(exitCode);
    }
}

Run the commands:

$ java -jar console.jar [arguments] [options]

About

Java port of the famous Symfony Console

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages