-
Notifications
You must be signed in to change notification settings - Fork 0
P-2379 Correct CLI filter examples #28
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,18 +35,24 @@ segments.command('list', { | |
|
|
||
| export interface CreateSegmentOptions { | ||
| title: string | ||
| filterSets: string | ||
| filters: string | ||
| } | ||
|
|
||
| export function buildCreateSegmentBody(options: CreateSegmentOptions) { | ||
| const parsedFilterSets = parseJsonArray(options.filterSets, '--filter-sets') | ||
| if (parsedFilterSets.some((item) => typeof item !== 'string')) { | ||
| throw new Error('--filter-sets must be a JSON array of strings') | ||
| const filters = parseJsonArray(options.filters, '--filters') | ||
| for (const filter of filters) { | ||
| if (!filter || typeof filter !== 'object' || Array.isArray(filter)) { | ||
| throw new Error('--filters must be a JSON array of {field, op, value} objects') | ||
| } | ||
| const { field, op } = filter as { field?: unknown; op?: unknown } | ||
| if (typeof field !== 'string' || field.length === 0 || typeof op !== 'string' || op.length === 0) { | ||
| throw new Error('--filters: each entry requires non-empty string "field" and "op" properties') | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| title: options.title, | ||
| filterSets: parsedFilterSets, | ||
| filters, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -60,15 +66,17 @@ segments.command('create', { | |
| description: 'Create a new user segment', | ||
| options: z.object({ | ||
| title: z.string().describe('Segment title'), | ||
| filterSets: z | ||
| filters: z | ||
| .string() | ||
| .describe('JSON array of filter set strings defining the segment'), | ||
| .describe( | ||
| 'JSON array of canonical {"field","op","value"} filter objects', | ||
|
Comment on lines
+69
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The required segment-create option was previously exposed and documented as Useful? React with 👍 / 👎. |
||
| ), | ||
| }), | ||
| examples: [ | ||
| { | ||
| options: { | ||
| title: 'Whales', | ||
| filterSets: '["net_worth_usd > 100000"]', | ||
| filters: '[{"field":"net_worth_usd","op":"gt","value":100000}]', | ||
| }, | ||
| description: 'Create a high-value segment', | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing scripts using the previously documented
profiles search --conditions ...option no longer supply any filter after this schema key is renamed tofilters; depending on incur's unknown-option handling, they either fail immediately or perform an unfiltered search. Keepconditionsas a deprecated alias that is normalized to the new canonicalfiltersrequest field so upgrading the CLI does not break or broaden existing searches.Useful? React with 👍 / 👎.