Swiftpack.co - Package - frazer-rbsn/SwiftArgs

SwiftArgs

A minimal, pure Swift library for making command-line tools / interfaces.

Travis build status codebeat SPM Swift version

SwiftArgs uses a very basic and limited parser for parsing commands, but it should suffice for basic usage requirements. You can use SwiftArgs when making a command-line interface in Swift and let it do the parsing work for you.

Contributions welcome.


Install

Using Swift Package Manager:

dependencies: [
  .Package(url: "https://github.com/frazer-rbsn/SwiftArgs", majorVersion: 1.1),
]

Limitations

  • Hasn't been tested on Linux.
  • Currently no support for subcommands
  • Doesn't support short-form option switches yet, e.g. mycommand -o

Github

link
Stars: 4

Dependencies

Used By

Total: 0

Releases

3.0.4 - 2019-11-10 12:44:52

  • Updated to Linux-compatible package structure
  • Fixed crash when no arguments passed

3.0.3 - 2019-09-15 17:56:44

Test structure

3.0.2 - 2019-09-15 17:52:38

  • Added tests placeholder

3.0.1 - 2019-09-14 20:38:11

  • Manifest fix

3.0.0 - 2019-09-14 19:48:32

  • Extensible CommandName, ArgumentName and OptionName structs, used in the same way as Foundation's Notification.Name.
  • Parsed models use dictionaries with the related name struct as the key.

2.0.2 - 2019-09-08 21:27:38

  • Parser fix

2.0.1 - 2019-09-08 21:25:08

  • Package manifest fix

2.0.0 - 2019-09-08 21:20:00

  • Re-write of whole project. Simplified parser. Commands are now built using a CommandBuilder.

1.1.0 - 2019-09-07 15:38:46

  • Update to Swift 5

Initial 1.0 Release - 2017-06-09 22:24:19

CommandParser.parseCommandLine(_:) no longer throws. Instead, you can handle parsing errors in a new CommandParserDelegate function, parserError(_:). This makes it easy to run parsing in a background thread and for better separation of concerns.

class Delegate : CommandParserDelegate {

  /**
   Called if there was a problem.
   */
  func parserError(error : CommandParserError) {
    //Handle error
  }
  
  /**
   Called if there were no command-line arguments supplied to your program.
   */
  func commandNotSupplied() {
    //Handle commands not supplied
  }
  
  /**
   Called if a command was parsed successfully.
   */
  func receivedCommand(command : Command) {
    //Handle successfully-parsed commands
  }
}

let delegate = Delegate()
let commandParser = CommandParser()
commandParser.parseCommandLine(delegate: delegate)