Skip to content

feat: add URL flag type with net/url support#494

Closed
happysnaker wants to merge 1 commit into
spf13:masterfrom
happysnaker:feat-url-flag-type
Closed

feat: add URL flag type with net/url support#494
happysnaker wants to merge 1 commit into
spf13:masterfrom
happysnaker:feat-url-flag-type

Conversation

@happysnaker

Copy link
Copy Markdown

Fixes #398

Adds a native URL flag type backed by url.URL from the standard library. Users can now define URL flags that automatically validate and parse URL values.

API

// FlagSet methods
fs.URL(name, default, usage) *url.URL
fs.URLP(name, shorthand, default, usage) *url.URL
fs.URLVar(p, name, default, usage)
fs.URLVarP(p, name, shorthand, default, usage)

// Package-level functions
URL(name, default, usage) *url.URL
URLP(name, shorthand, default, usage) *url.URL
URLVar(p, name, default, usage)
URLVarP(p, name, shorthand, default, usage)

Example

var endpoint = pflag.URL(endpoint, url.URL{Scheme: "https", Host: "api.example.com"}, "API endpoint URL")
pflag.Parse()
fmt.Println(endpoint.String()) // https://api.example.com

Adds a native URL flag type backed by url.URL from the standard
library. Includes URLVar, URLVarP, URL, URLP methods on FlagSet
and corresponding package-level functions.

Fixes spf13#398
@happysnaker

Copy link
Copy Markdown
Author

Closing due to Go 1.12 test failure — URL type requires more work for backward compatibility. Will re-approach.

@happysnaker happysnaker closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Support URLs as a native Flag type

1 participant