Implementing a console (CLI) in java

  • Thread starter raffaele castagno
  • Start date
R

raffaele castagno

I need to write a console to manage a game server. It's intended to be
like the one of FreeCIV, if you know it.
Anyway, it's simply a generic console.
I'm planning to use the sourceForge project JLine to manage the user input
(name completion, command history, etc), and the jacarta.commons CLI to
parse command lines.
The last obvious step is the effective execution of the given commands. Of
course there are many ways to do it, but at the present time I don't know
what is the best way to do it.
Reading some docs about pattern, I've seen the Comman pattern, and it
seems to be something similar to what I need. But, I can't find a usable
implementation of this pattern.
So, the question is:
can you tell me if the command pattern is good for my goal? If not, what
is the best way to do the work?

Thanks you!
Greetings!

Raffaele
 
P

Paul Lutus

raffaele said:
I need to write a console to manage a game server. It's intended to be
like the one of FreeCIV, if you know it.
Anyway, it's simply a generic console.
I'm planning to use the sourceForge project JLine to manage the user input
(name completion, command history, etc), and the jacarta.commons CLI to
parse command lines.
The last obvious step is the effective execution of the given commands. Of
course there are many ways to do it, but at the present time I don't know
what is the best way to do it.

The best way to do it depends on what the commands are and how they work.
Reading some docs about pattern, I've seen the Comman pattern, and it
seems to be something similar to what I need. But, I can't find a usable
implementation of this pattern.
So, the question is:
can you tell me if the command pattern is good for my goal?

That depends on your goal, which you haven't described except in the most
general way. So the answer is, generally, maybe, yes.
 
R

Raffaele Castagno

Paul Lutus said:
raffaele castagno wrote:
That depends on your goal, which you haven't described except in the most
general way. So the answer is, generally, maybe, yes.

Well, you are right..

This console is for a game I'm planning to write:
sourceforge.net/projects/strategic/
It's still at a very early stage of planning, nothing usable yet.

There will be two types of commands: built-in and pluggable.
The built-in command include all core functions and generic commands.
Since the function of the console is to manage gameservers, there will
be commands to star/stop servers, manage users, load plugins, and so
on. The plugins are simply "game modules", ie packages wich contains
specific game files and commands.
The core program will load plugins, and also their specific command
list.
Pluggable commands are game related: create new game,
create/destroy/move entities, join users, save/load games.
Of course I need to find a way to avoid conflicts, for example using
some king of context manager. An idea can be to implement a DBMS
console (ex.mysql console) style syntax:
there is a core set of commands, and you can change context with the
"use DBName" command. In my case, the change of context will also give
acces to specific-context commands.

What I need now is something able to read the "commanLine" that I get
from jakarta.CLI, and find the right method in the build-it or
pluggable command list.
Of course, I could write it myself, I already have some ideas, but I'd
rather to use an existing library, possibly free and open, if there is
one...

Greeting

Raffaele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top