CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Creating a tool which has a CLI

 



rietchel
Novice

Sep 26, 2017, 10:50 PM

Post #1 of 4 (1184 views)
Creating a tool which has a CLI Can't Post

Hi,

Wondering if its possible to create a tool with perl that has its own CLI? Maybe perl isn't the right language for it, but my idea is basically a XML editor which allows users to interactively modifiy their file. Now I know there are existing GUI's out there, but they don't have some of the features I want to incorporate. For example lets say my tool is called xml_editor_1.0

Run from UNIX/LINUX command line:

% xml_editor_1.0 -cli

Now the tool is 'loaded':

xml_editor_1.0>

I'm thinking then the user can 'read' the xml file which opens an existing XML file and loads the root node. Any further actions taken will be done on the loaded XML. I will also XML::libXML (or similar) as a base to create all of the unique tool commands.

xml_editor_1.0> read <path_to_XML_file>

Or lets say user wants to create a new file, it would use the schema as a framework to create an 'empty' file:

xml_editor_1.0> create -xml my_new_xml.xml

Then from there if they want to add or remove major elements they can do it through some custom made commands. Below are some random examples, although there are a ton of other different actions I would want to incorporate as well:

xml_editor_1.0> add -element blablah <-- creates a new element
xml_editor_1.0> delete -element blahblah <-- remove element
xml_editor_1.0> edit -element name <-- edit field of elemnent
xml_editor_1.0> save my_new_xml2.xml <-- save current xml database to new file
xml_editor_1.0> create -pdf -root my_new_xml2.xml <-- creates other output types
xml_editor_1.0> validate -xml my_new_xml2.xml <-- makes sure complies to schema
xml_editor_1.0> convert -xml my_new_xml2.xml <-- converts other schemas into local schema
etc

This is a few basic commands but I have thought up a ton of other commands which would be useful in my application. I also think it would be cool if I could somehow incorporate PERL syntax to allow users to create their own loops and variables to automate the creation/editing process. Eventually I'm hoping to create a GUI for this as well so people can choose between running on the tool CLI or doing things through the GUI.

So is this possible via perl, or should I be looking elsewhere?

Thanks!


Laurent_R
Veteran / Moderator

Sep 26, 2017, 11:05 PM

Post #2 of 4 (1182 views)
Re: [rietchel] Creating a tool which has a CLI [In reply to] Can't Post

Hi,
I don't know whether Perl is the best language for that, but I am pretty sure that Perl is very well suited for this type of application.


rietchel
Novice

Sep 27, 2017, 1:15 AM

Post #3 of 4 (1179 views)
Re: [Laurent_R] Creating a tool which has a CLI [In reply to] Can't Post

Thanks for the feedback. I think a way to do this is somehow create an interactive interface to allow user input. I know in C++ just doing a while loop and grabbing cin will do something similar (unless exit is specified). I'll see if I can try to replicate this in perl.


Laurent_R
Veteran / Moderator

Sep 27, 2017, 9:50 AM

Post #4 of 4 (1167 views)
Re: [rietchel] Creating a tool which has a CLI [In reply to] Can't Post

Yes, that would be the idea: creating an endless loop to capture user input; then you process user input and call subroutines for doing what is needed. And using loop control (such as last) to terminate the appliation when the user wants to exit.

There must be scores of such applications available on the net, try to find some and look at what they do and how. I'm sure you'll be able to find many ideas on how to best do the things.

There might also be ready-made modules (or possibly frameworks) on the CPAN, check on the CPAN.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives