Skip to content

Configuration Builders #36

Description

@cmcgee1024

I would like to model command-line tools using my own Swift types for better type safety and testability and use that with the new Subprocess proposal. Here is an example:

try await run(
    Tar().extract(.archive("foo.tar.gz")),
)

With a Swift type like this it can help to find simple typos on commands, arguments, and flags at compile time instead of runtime. Over time they can become more abstract, modelling more complex tool interactions with a custom API suited to a particular module's needs. The command can then encapsulate the creation of the executable, arguments and environment variables, most of which are what are available through the Subprocess.Configuration struct.

However, there doesn't appear to be a natural way to plug in these command wrappers into the call sites of the Subprocess API as shown in the above example. They would need to extend the Subprocess.Configuration struct, and inherit its methods.

If the SubProcess.Configuration was a protocol instead of a struct then a custom type could conform to that protocol to provide the necessary information to be used in the Subprocess.run() like this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions