Giter VIP home page Giter VIP logo

argparse's Introduction

ArgParse

๐Ÿ“‹ Simple command-line argument parser for Visual Basic 6

Dependencies

  • Microsoft Scripting Runtime (sccrun.dll)

Usage

UNIX-style parsing

Dim Args As New ArgParser
With Args
    .MarkAsOption "option1", "option2", "option3"
    '--option1, --option2 and --option3 will be marked as "options" with values

    .SetAlias "option3", "o3"
    'You can also set shorter aliases for flags and options

    .Parse "verb1 verb2 ""C:\path\to\example folder"" --option1 value1 --option2=value2 -o3 value3 --flag1 --flag2"
    'Parse the command-line arguments.
    'You can pass in "Command$" in pratical use.
    
    'Show results
    Dim PlainArg As Variant
    For Each PlainArg In .PlainArgs
        Debug.Print PlainArg
    Next

    Debug.Print .Options("option3")
    Debug.Print .FlagEnabled("flag1")
End With

DOS-style parsing

ArgParse also supports MS-DOS style options which uses slashes as marks and case-insensitive.

Dim Args As New ArgParser
With Args
    .OptionsStyle = DOS
    .SetAlias "Option3", "O3"
    .Parse "Verb1 Verb2 ""C:\path\to\example folder"" /Option1 Value1 /Option2:Value2 /O3 Value3 /Flag1 /Flag2"

    Dim PlainArg As Variant
    For Each PlainArg In .PlainArgs
        Debug.Print PlainArg
    Next

    Debug.Print .Options("option3")
    Debug.Print .FlagEnabled("flag1")
    'This will work because DOS mode is case-insensitive
End With

Walking through plain arguments

Calling Args.NextArg and Args.ThisArg will let you walking through all the plain arguments.

This will be useful in Select Case ... statement to select the verb.

Dim Args As New ArgParser
Args.Parse "bisect bad"
Select Case Args.NextArg
    Case "init"
    Case "clone"
    Case "commit"
    Case "bisect"
    Select Case Args.NextArg
        Case "start"
        Case "good"
        Case "bad"
        Case Else
        '...
    End Select
    Case Else
        Debug.Print "Unsupported operation: " + Args.ThisArg
End Select

argparse's People

Contributors

chiyuki0325 avatar

Watchers

 avatar

Forkers

xxdoc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.