@jinshuju/cli 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,29 @@
1
1
  import { FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, MINE_OPTION, PAGINATION_OPTIONS, SORT_OPTION, UsageError } from '../options.js';
2
2
  import { FOLDER_OPTION, LISTING, PREVIEW_OPTION, YES_OPTION, confirmed, filters, given, keywords, overriding, paging, payload, refuseWithMine, requiredOption, sort, trash } from './shared.js';
3
3
  import { validateContainerPayload } from '../payload.js';
4
- import { bodyChoices, call } from '../spec.js';
4
+ import { bodyChoices, bodyKeys, call } from '../spec.js';
5
5
  import { readableSize, upload, uploadedId, uploadFormImage } from './upload.js';
6
6
  import { isRecord } from '../values.js';
7
+ /**
8
+ * Every key setting takes, from the spec. The paragraphs above explain a few;
9
+ * a key the help never names reads as one the CLI cannot write.
10
+ */
11
+ function settingKeys() {
12
+ const keys = bodyKeys('createForm', 'setting');
13
+ if (!keys)
14
+ return [];
15
+ const lines = ['Every key setting takes, in `form create` and `form edit` alike:'];
16
+ for (const key of keys) {
17
+ const last = lines.length - 1;
18
+ const joined = `${lines[last]} ${key},`;
19
+ if (last > 0 && joined.length <= 78)
20
+ lines[last] = joined;
21
+ else
22
+ lines.push(`${key},`);
23
+ }
24
+ lines[lines.length - 1] = lines[lines.length - 1].replace(/,$/, '.');
25
+ return [...lines, ''];
26
+ }
7
27
  /**
8
28
  * The shape behind `--json` on a form, shown rather than described: `fields` is
9
29
  * the part nothing else hints at, and one choice field carries more of the
@@ -47,6 +67,7 @@ const FORM_PAYLOAD = [
47
67
  'not-open and fill-limit messages. A key left out keeps its text, and ""',
48
68
  'puts the default back.',
49
69
  '',
70
+ ...settingKeys(),
50
71
  'A form reads its fields back in the shape written here, each with the',
51
72
  'api_code the backend assigned, and a field read goes back through',
52
73
  '`field update` as it came. `field types` lists the types to write, and',
@@ -536,7 +557,7 @@ export const FORM = [
536
557
  description: 'The payload carries the operations to apply: name, description, setting, layout, and fields as ' +
537
558
  '{add, update, update_choices, remove}. Only what is named changes. Switching layout keeps every ' +
538
559
  'field; the card layout hides the ones it cannot show and the classic layout shows them again. `form create --help` ' +
539
- 'shows what setting takes, the close rules among it; `form setting edit` writes the few settings this ' +
560
+ 'lists every key setting takes and explains the close rules among them; `form setting edit` writes the few settings this ' +
540
561
  'payload cannot, the WeChat share card among them. Display and redirect rules have commands of their ' +
541
562
  'own: `form rule edit` and `form redirect-rule edit`.',
542
563
  args: [{ name: 'form', required: true, description: 'Form token' }],
package/dist/spec.d.ts CHANGED
@@ -135,3 +135,9 @@ export declare function choices(id: OperationId, path: string): readonly string[
135
135
  * dots and steps into a list's items with `[]`: `fields[].type`.
136
136
  */
137
137
  export declare function bodyChoices(id: OperationId, path: string): readonly string[] | undefined;
138
+ /**
139
+ * The keys an object in a JSON body takes, walked to as `bodyChoices` walks:
140
+ * `setting`. For help that has to name every key, which a hand-kept list
141
+ * would name fewer of as the API learns more.
142
+ */
143
+ export declare function bodyKeys(id: OperationId, path: string): readonly string[] | undefined;
package/dist/spec.js CHANGED
@@ -208,6 +208,19 @@ export function choices(id, path) {
208
208
  export function bodyChoices(id, path) {
209
209
  return enumOf(walk(OPERATIONS[id].body?.content['application/json'], path.split('.')), `${id} ${path}`);
210
210
  }
211
+ /**
212
+ * The keys an object in a JSON body takes, walked to as `bodyChoices` walks:
213
+ * `setting`. For help that has to name every key, which a hand-kept list
214
+ * would name fewer of as the API learns more.
215
+ */
216
+ export function bodyKeys(id, path) {
217
+ const schema = walk(OPERATIONS[id].body?.content['application/json'], path.split('.'));
218
+ const keys = Object.keys((schema && resolved(schema).properties) ?? {});
219
+ if (keys.length > 0)
220
+ return keys;
221
+ unanswered.push(`${id} ${path}`);
222
+ return undefined;
223
+ }
211
224
  /** The schema the steps lead to: each names a property, and `[]` steps into a list's items. */
212
225
  function walk(from, steps) {
213
226
  let schema = from;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {