JohnSundell/Marathon

Different behavior for arguments with spaces

jeffctown opened this issue ยท 4 comments

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?

Hi @jeffctown ๐Ÿ‘‹ Thanks a lot for this bug report - I have fixed it in this PR: #115.

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

I can confirm your fix works! ๐Ÿพ๐Ÿพ๐Ÿพ

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

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