Add --json/jsonl and --params options#120
Conversation
|
Hmm there are 12 identical implementations of |
fw42
left a comment
There was a problem hiding this comment.
Hmm I don't know if this is really an improvement. What is the motivation for this PR? Did anyone request this feature? I feel like if you're using --json, you might as well just use curl. This seems to add some extra complexity and quite a bit of extra code (this PR is over 1000 lines of new code) for a small edge case.
| } | ||
| } | ||
|
|
||
| func TestChannelOptionsMarshalJSON_WithoutExtra(t *testing.T) { |
There was a problem hiding this comment.
This test seems a bit unnecessary. It's already tested implicitly through the other one, isn't it?
|
|
||
| // size (number of results per batch) is "limit" in this API endpoint | ||
| // size is an important parameter for iteration | ||
| // so pick it up from extra if it's given |
There was a problem hiding this comment.
Hm why is that needed if we already have size and limit?
There was a problem hiding this comment.
size (limit in the hostname API) is an important param for iterating :
t.HasMore = len(r.Results) >= it.sizeIf it's given from --params, the iterator needs to pick it up from there.
There was a problem hiding this comment.
What I meant is: Why do we have to be able to extract size from the new extra field if we already have a --size parameter that could be used? I thought this was all to give access to fields that we haven't implemented yet (but size is already implemented, so why do we need to be able to also use it via the extra thing)?
| OverrideSafety *string `json:"overrideSafety,omitempty"` | ||
| Country *string `json:"country,omitempty"` | ||
| URL string `json:"url"` | ||
| CustomAgent string `json:"customagent,omitempty"` |
There was a problem hiding this comment.
Why all the changes from *string to string?
There was a problem hiding this comment.
Oops, I have to comment that.
I noticed that using pointer against strings in the struct is not meaningful.
type A struct {
foo *string `json:"foo,omitempty"`
}
type B struct {
foo string `json:"foo,omitempty"`
}
Both produce {} in Go so.
Also using pointer in the struct is inconsistent since other JSON related structs don't use pointer.
| } | ||
|
|
||
| func AddParamsFlag(cmd *cobra.Command) { | ||
| cmd.Flags().String("params", "", "Query string parameters as JSON (e.g. '{\"key\":\"value\"}')") |
There was a problem hiding this comment.
Why as JSON? Seems a bit unintuitive. Why not -params "foo=bar&bla=blabla" 🤷♂️
| } | ||
|
|
||
| func AddJSONLFlag(cmd *cobra.Command) { | ||
| cmd.Flags().String("jsonl", "", "JSONL payload to send as request bodies (one JSON payload per line)") |
There was a problem hiding this comment.
Hm how do I use this command? Do I have to pass a string with multiple lines as parameter? like -jsonl "{ "foo": "bar" }\n{"bla": "bla"}\n"?
There was a problem hiding this comment.
Yes that's right.
There was a problem hiding this comment.
Yes that's right.
I'm confused. In the docs below it sounds like the JSONL payload comes from either a file that's being read or from STDIN. But here you just said that the payload is being given as a command line argument. Which one is it?
|
|
||
| var createCmdExample = ` urlscan pro channel create -n <name>` | ||
| var createCmdExample = ` urlscan pro channel create -n <name> | ||
| urlscan pro channel create --json '{"channel":{"name":"...","type":"webhook","webhookURL":"https://..."}}'` |
There was a problem hiding this comment.
Hm adding it to the example like this kind of makes it look like that this is the recommended way that we want people to use this tool. Whereas it's more meant like a last resort in case we forget to implement something, right?
Co-Authored-By: Claude <noreply@anthropic.com>
fw42
left a comment
There was a problem hiding this comment.
I'm not convinced this PR is an improvement. Seems like a lot of extra code and additional complexity. I'll leave it up to you to decide whether to merge it though.
|
|
||
| // size (number of results per batch) is "limit" in this API endpoint | ||
| // size is an important parameter for iteration | ||
| // so pick it up from extra if it's given |
There was a problem hiding this comment.
What I meant is: Why do we have to be able to extract size from the new extra field if we already have a --size parameter that could be used? I thought this was all to give access to fields that we haven't implemented yet (but size is already implemented, so why do we need to be able to also use it via the extra thing)?
| } | ||
| if json != nil { | ||
| opts = append(opts, api.WithIncidentExtra(json)) | ||
| } else { |
There was a problem hiding this comment.
Am I reading this right that the new --json command and the existing command flags can't be combined? If there is a json then all the other commands will just be ignored?
| } | ||
|
|
||
| func AddJSONLFlag(cmd *cobra.Command) { | ||
| cmd.Flags().String("jsonl", "", "JSONL payload to send as request bodies (one JSON payload per line)") |
There was a problem hiding this comment.
Yes that's right.
I'm confused. In the docs below it sounds like the JSONL payload comes from either a file that's being read or from STDIN. But here you just said that the payload is being given as a command line argument. Which one is it?
| urlscan scan bulk-submit list_of_urls.txt <url>` | ||
| urlscan scan bulk-submit list_of_urls.txt <url> | ||
| # submit with JSONL file where each line is a JSON payload | ||
| urlscan scan bulk-submit --jsonl payloads.jsonl |
There was a problem hiding this comment.
Where is this loading for reading .jsonl files? I don't see it
This PR adds
--json/jsonl(JSON payload) and--params(query parameters) for making this CLI is more agent frendly. (ref. https://justin.poehnelt.com/posts/rewrite-your-cli-for-ai-agents/)I think this is good for human too. A user can send an arbitary request even if we forget adding a new flag so.
How It Works
--json/--paramsis mapped asextrafield in a structextrafield value to orverride data to be sent (JSON body, query parameters)