Jump to content

CLI.au3 easy using of command line parameter


 Share

Recommended Posts

Hi,

next week my holiday starts ... and I'd like to create an nice UDF

I would like to create a cli.au3 in Autoit --> for Autoit.

What it is supposed to do?

In Perl or Java there a funcs that deal with the arguments passed by commandline parameters to your code.

Like myExe.exe -i inputFilePath -o outputFilePath -t -s

Till now, it is up to you coding something like this:

If $CmdLine[0] > 0 Then
    Select $CmdLine[1]
        Case $CmdLine[1] == "Hello"
            out("hello")
        Case $CmdLine[1] == "Test"
            ConsoleWrite("Test" & @CRLF)
        Case Else
            out("unknown Parameter!")
    EndSelect
Else
    MsgBox(0, "Info", "No parameter --> exit", 4)
    Exit (0)
EndIf

Func out($txt)
    MsgBox(0, "Info", $txt)
EndFunc   ;==>out

I would like to create some func to make things easier to use, but I need some suggestions before I start.

What funcs are needed?

I thought it would be nice to have something like this:

Func _setVersion($s_version = '-version', $icon = 64, $s_Title = @ScriptName, $s_Message = 'Version : ', $i_timeout = 10)

If one of the parameters is -version then show this MsgBox ...

Func _setHelpMsg($s_help = '-?', $icon = 64, $s_Title = @ScriptName, $s_Message = '', $i_timeout = 10)

If one of the parameters is -help or -? then show this MsgBox ...

Func _setParameter($mandatoryParameter_A, $optionalParameter_A = '')

You can set parameters that have to be passed by otherwise the usage (Msgbox from setHelpMsg) will be shown and script exits.

The func returns an 2D array with parameter[0] and parameterValue[1] e.g:

[0][0] = count of parameters

[1][0] = i

[1][1] = inputFilePath

...

Or a func like getCLIValue('-i') return is inputFilePath and so on.

Addional debug func two parameters (debug and level)

If one of the parameter is -debug then a global variable called $b_Debug = 0 is set to True

and -debuglevel sets the level (like 0=info=much logging, 1=warn=log only warnings, 2=fatal=log only errors)

Questions:

What should happen to parameters passed twice?

What should happen to unexpected parameters?

Should there be an option to set sign to determine parameters like (-,/,--)?

Should there be an sort option?

Thanks for you suggestions.

Questions over all, do you think this can come in handy / be useful?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Please don't use font colors. Just because something is visible with the theme you happen to be using doesn't mean it's visible with themes others happen to be using.

I would have a look at *nix's getopts library, or whatever it's called. I know there's a library for *nix, at any rate, which tries to make command line arguments easier to implement. That seems like it'd be a good place for ideas.

Link to comment
Share on other sites

Please don't use font colors. Just because something is visible with the theme you happen to be using doesn't mean it's visible with themes others happen to be using.

I would have a look at *nix's getopts library, or whatever it's called. I know there's a library for *nix, at any rate, which tries to make command line arguments easier to implement. That seems like it'd be a good place for ideas.

Hi,

thx for reply. Okay, I'll try to avoid font colors. :P

I know Getopts and I already had a short look at cpan or here : http://world.std.com/~swmcd/steven/perl/pm/getopt.html

Do you think this can be useful? Then I'll try my best.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Anything you do here will be appreciated. Supporting Valik's comments -- if there is a defacto standard, it would be best to go that direction.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Hi,

thx. I'll read a bit of that stuff and post a little starting script soon.

Never thought of implementing something big like GetOps with X different ways. I just wanted to create some little funcs to avoid those select case things and so on - to write for everybody who uses commandline parameters in thier scripts.

I'll find an answer to my questions mentioned above and I'll react on that cases. we'll see if you can live with that. :P

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 2 months later...

While not as feature rich as it could be, here's a link to a getopt port I used for my base32 script.

Link to comment
Share on other sites

This sounds interesting. So it will support multiple arguments?

Yes. The base32 script is simple enough to act as an example. Usage is fairly easy.
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

the question is how far you would like to go?

I thought of just implementing the basics as mentioned above.

Maybe an udf for this could lead to kind of standardization for Autoit scripts like -? and /? = show help dialog for commandline parameters. -version and /version show version dialog of script and used Autoit version and -debug (1,2,3..) sets the debuglevel.

and funcs to easily get the parameters in script like _getParameter(i) and so on.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

My Process Watcher made use of arbitrarily ordered parameters, if anyone is interested in tearing it apart for an example. I just remembered that.

Hi,

give it a go and show what you did. Anybody interested in an udf for that?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 2 years later...

While not as feature rich as it could be, here's a link to a getopt port I used for my base32 script.

(I know this is an old thread, but for the benefit of those searching the forums..)

eltorro, I finally followed your signature to "some of your scripts on Google code" and was delighted to see you have a newer version called OptParse which allows non-option arguments as well. :idea:

Link to comment
Share on other sites

  • 2 months later...

Appologies as this is an old thread, but I'm trying to find a nice UDF to quickly and easily add command line options to autoit scripts.

As daddydave said above, eltorro's OptParse does indeed seem to be what I'm after, but have hit a problem or two.

"Duplicate Arguments" don't seem to cause an error as they should, seems to be just ignored.

If you use the --switch format, it first cuts it down to -switch which is fine until it errors and says that -switch is not a valid switch, but actually what they used was --switch possibly this is nit picking, but thought it worth mentioning.

I don't see an option for a hidden switch, one that doesn't show up in the usage listing but does work, possible reasons for this are new/beta switches/functions not yet fully supported, or more advanced options only listed in advanced user documentation.

Having "short" and "long" will most likely do in 90% of cases, but it would be nice if one line could represent what to do if any of the following are used: /? /h /help /usage (just as an example of multiple possible identical switches).

Have PM eltorro, and looking through the UDF to work it out, but just wondered if anyone else was or has done this?

Link to comment
Share on other sites

I created an UDF to parse a commandline into a 2D-Array, but I did not create any other functions for the params. You could use the _Array-functions, though.

http://www.autoitscript.com/forum/index.php?showtopic=110189&view=findpost&p=774455

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I created an UDF to parse a commandline into a 2D-Array, but I did not create any other functions for the params. You could use the _Array-functions, though.

http://www.autoitscript.com/forum/index.php?showtopic=110189&view=findpost&p=774455

Was really hoping not to have to re-invent this and write it all :blink: I've got enough problems with StringSplit and Multidimensional arrays...

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...