Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for url.URL argument type #37

Closed
oakad opened this issue Aug 31, 2017 · 7 comments
Closed

Add support for url.URL argument type #37

oakad opened this issue Aug 31, 2017 · 7 comments

Comments

@oakad
Copy link

oakad commented Aug 31, 2017

Urls are pretty common args to go apps and it makes sense to support url validation early on. The alternative is to rely on rather ugly boilerplate in all apps in need of that feature.

The example of ugly boilerplate that better be hidden inside the lib:

type urlValue struct {
	u *url.URL
}

func (uv *urlValue) Parse(s string) error {
	u, err := url.Parse(s)
	*uv.u = *u
	return err
}

cli.RegisterFlagParser("urlParser", func(ptr interface{}) cli.FlagParser {
	return &urlValue{
		u: ptr.(*url.URL),
	}
})
@suntong
Copy link
Collaborator

suntong commented Sep 4, 2017

Is "Reader read from url", #34, what you are looking for?

If yes, take a look at
https://github.com/suntong/cascadia#twitter-search

@oakad
Copy link
Author

oakad commented Sep 5, 2017

Not at all.

I'm talking about situations of:
app -arg http://google.com

with args struct:

type rootArgs struct {
	cli.Helper
	someArg url.URL `cli:"arg" usage:"give me some url"`
}

@suntong
Copy link
Collaborator

suntong commented Sep 5, 2017

Oh, ok. Is url.URL something new or already supported?

@oakad
Copy link
Author

oakad commented Sep 5, 2017

Something new compared to what? It's an stdlib type (import net/url), which can parse and validate urls. I'm using it right now with a help of a custom parser boilerplate (as outlined in my OP). However, considering that validating urls is a pretty common task in Go world, I hoped that it can be incorporated into the "cli" library as one of the basic types (similar to string and int).

@suntong
Copy link
Collaborator

suntong commented Sep 8, 2017

@mkideal is not active nowadays as he used to be.
Previously bugs get fixed within days, usually within 48 or even 24 hours.
Now he's in sleeping mode that nobody seems to be able to wake him up.

I mean, you'll have better chances if you submit a PR, with some well-thought test cases covered.

@oakad
Copy link
Author

oakad commented Sep 8, 2017

I have decided to abstain from PRs on github these days. :-)

Everybody says, "submit a PR", but when someone does it always deteriorates into a never ending PR-ball, which usually makes a rather lousy pastime.

@suntong
Copy link
Collaborator

suntong commented Sep 8, 2017

oh, that's an odd story, but good to hear.

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

No branches or pull requests

3 participants