0001    //
0002    //  Args.swift
0003    //  Swiftline
0004    //
0005    //  Created by Omar Abdelhafith on 25/11/2015.
0006    //  Copyright © 2015 Omar Abdelhafith. All rights reserved.
0007    //
0008    
0009    
0010    /// Return the command line arguments passed to the script
0011    public class Args {
0012      
0013      /// Return the list of arguments passed to the script
0014      public static var all
Args.swift:31
    let parsedArgs = ArgsParser.parseFlags(all)
: [String] { 0015 return ProcessInfo.arguments 0016 } 0017 0018 static var cachedResults
Args.swift:26
    if let result = cachedResults where ProcessInfo.cacheResults {
Args.swift:46
    cachedResults = ParsedArgs(command: commandName, flags: parsedFlags, parameters: arguments)
Args.swift:47
    return cachedResults!
: ParsedArgs? 0019 0020 /// Return a parsed list of arguments containing the flags and the parameters passed to the scripts 0021 /// The flags are recognized as short flags `-f` or long flags `--force` 0022 /// The flag value will be the argument that follows the flag 0023 /// `--` is used to mark the terminatin of the flags 0024 public static var parsed: ParsedArgs { 0025 0026 if let result = cachedResults where ProcessInfo.cacheResults { 0027 return result 0028 } 0029 0030 var parsedFlags = [String: String]() 0031 let parsedArgs = ArgsParser.parseFlags(all) 0032 0033 parsedArgs.0.forEach { 0034 parsedFlags[$0.argument.name] = $0.value ?? "" 0035 } 0036 0037 var arguments = parsedArgs.1 0038 0039 // the first argument is always the executable's name 0040 var commandName = "" 0041 if let firstArgument = arguments.first { // just in case! 0042 commandName = firstArgument 0043 arguments.removeFirst(1) 0044 } 0045 0046 cachedResults = ParsedArgs(command: commandName, flags: parsedFlags, parameters: arguments) 0047 return cachedResults! 0048 } 0049 } 0050 0051 0052 public struct ParsedArgs
Args.swift:18
  static var cachedResults: ParsedArgs?
Args.swift:46
    cachedResults = ParsedArgs(command: commandName, flags: parsedFlags, parameters: arguments)
Args.swift:24
  public static var parsed: ParsedArgs {
{ 0053 /// The name of the executable that was invoked from the command line 0054 public let command: String 0055 0056 /// Parsed flags will be prepred in a dictionary, the key is the flag and the value is the flag value 0057 public let flags: [String: String] 0058 0059 /// List of parameters passed to the script 0060 public let parameters: [String] 0061 }