JohnSundell / Marathon

[DEPRECATED] Marathon makes it easy to write, run and manage your Swift scripts πŸƒ
MIT License
1.86k stars 78 forks source link

Different behavior for arguments with spaces #114

Closed jeffctown closed 7 years ago

jeffctown commented 7 years ago

Hey there. I'm new to Marathon, but have been loving it so far. I started working on a script to post a message to the Slack API that I would like to run using marathon, but I have run into issues when an argument has spaces in it. Running this script via the executable seems to have a different behavior than running the script using Marathon.

Here is my Marathonfile:

https://github.com/JohnSundell/Files.git
https://github.com/kareman/SwiftShell.git
https://github.com/kareman/Moderator.git

Here is the content of my script's main.swift:

import Foundation
import Moderator
import SwiftShell

let arguments = Moderator(description: "Post a message to Slack.")

let messageArg = arguments.add(Argument<String?>.optionWithValue("m", name: "message", description: "The message to post."))

do {
    try arguments.parse()

    print("*** MessageArg.value: \(messageArg.value ?? "nil")")

    guard let message = messageArg.value else {
        throw ArgumentError(errormessage: "Slack message not found.", usagetext: "use -m Message")
    }

    print("*** Message: \(message)")    

} catch {
    print("*** FAILURE!")
    print(error)
    exit(Int32(error._code))
}

I originally posted an issue with the Moderator repo thinking it was an issue with that project, but the owner of Moderator showed be that what I run this script via the executable it works fine. It is only when I run this script using Marathon that I run into issues.

$ marathon run ~/top/post-to-slack.swift -m "Two Words"
*** FAILURE!
Unknown arguments: Words
Post a message to Slack.

Usage: post-to-slack
  -m <message>:
      The message to post.

$ ./.build/debug/post-to-slack -m "Two Words"
*** MessageArg.value: Two Words
*** Message: Two Words
$ marathon run ~/top/post-to-slack.swift -m 'Two Words'
*** FAILURE!
Unknown arguments: Words
Post a message to Slack.

Usage: post-to-slack
  -m <message>:
      The message to post.

$ ./.build/debug/post-to-slack -m 'Two Words'
*** MessageArg.value: Two Words
*** Message: Two Words

Using single or double quotes for argument values does not seem to work with marathon. How can I run a script in marathon that has an argument value with spaces?

JohnSundell commented 7 years ago

Hi @jeffctown πŸ‘‹ Thanks a lot for this bug report - I have fixed it in this PR: https://github.com/JohnSundell/Marathon/pull/115.

jeffctown commented 7 years ago

@JohnSundell you are the man. thanks so much. i will try it out tonight.

jeffctown commented 7 years ago

I can confirm your fix works! 🍾🍾🍾

$ marathon run post-to-slack.swift -m "Two Words." MessageArg.value: Two Words. Message: Two Words.

JohnSundell commented 7 years ago

Awesome! πŸŽ‰ Happy scripting πŸ˜€