Add arguments to "swift run" without ArgumentParser

I am trying to elaborate my project ideas for GSoC 2018 so I am ready when applications open. We were taught to use the Swift Package Manager at school, and I have been eagerly using it for all my projects since then. I think it makes my life a lot easier when I need to work with multiple projects and I love the testing function. While I think it’s a delight to use the Swift PM, I would love to see in it some functionalities other modern package managers have. I have been checking the project ideas for GSoC 2018, and I am thrilled to see some important features listed there. I am very excited that I might have a chance to work on some of them myself!

While developing command line applications, sometimes I need to take in arguments. I realized that when I use "swift run ", I don’t have access to ARGV. Instead, I need to go to the build folder, and run the executable on command line with my arguments. While looking for a solution, I came across ArgumentParser source code, but there wasn’t much documentation about it. Also, if I need to access only one argument, I might not necessarily want to implement the whole thing.

What is your idea on this? Do you think there is one proper way of doing this, and that is the ArgumentParser, or do you think this is an idea that might get traction? I would like to know what the architects had in mind when they were designing this. Thank you!


Definitely, we lack a lot of features but we're slowly making progress!

You should be able to pass arguments to your executable if you mention the executable name in the swift run invocation. Example:

swift run executable_name [arguments]
swift run myexec --foo 1

SwiftPM's ArgumentParser is a general purpose argument parser that can be used in other packages. You can add a dependency to Swift package manager repository and import Utility to use it. However, beware that the APIs are not marked stable and will change without notice. We don't have good documentation yet but you can follow this blog post to get started if you're interested.

Phew! My problem wasn’t even a problem. Thank you very much for your detailed response Ankit!