apple / apple/swift-argument-parser

Option parsing from environment variables

Open
#4 14 comments 23 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 14h
Merged PRs (30d)
15

Description

It would be super nice/helpful to parse an options value from an Environment variable value as well taking what is passed in the command line call as the priority over the ENV variable. For CLI's that run in CI or automated environments this is super helpful as it would allow not having to print the value in the ENV variable and could keep it hidden. Not only that but it would be very convenient for repeated uses on commands!

```swift
import ArgumentParser

struct MyCommand: ParsableCommand {
@Option(name: .shortAndLong, help: "The API Secret.", env: "SERVICE_API_SECRET")
var secret: String
}
```

**Usage:**
`mycommand --secret QWERTY12345`
or
`mycommand` (where `SERVICE_API_SECRET='QWERTY12345'`

Contributor guide

Open the contributing guide

Research direction

Start by tracing Swift ArgumentParser's option parsing entry point and how command-line values are resolved. Define how the proposed environment-variable annotation is represented, ensure command-line arguments take precedence, and add coverage for both sources and the missing-value case; done means the example works without exposing the secret on the command line.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.