@xano/cli 1.0.3-beta.7 → 1.0.3-beta.8

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.
package/README.md CHANGED
@@ -47,6 +47,13 @@ xano auth
47
47
  xano auth --origin https://custom.xano.com
48
48
  xano auth --insecure # Skip TLS verification (self-signed certs)
49
49
  xano auth --no-browser # Headless login (no local callback server)
50
+
51
+ # Pre-select instance/workspace/branch and profile name (skips the pickers)
52
+ xano auth -i my-instance -w 5 -b dev -p staging
53
+ xano auth --instance my-instance --workspace "My Workspace" --branch dev --profile staging
54
+
55
+ # Pass "" to take a picker's default: skip workspace, use live branch, default profile name
56
+ xano auth -i my-instance -w 5 -b "" -p ""
50
57
  ```
51
58
 
52
59
  The default flow starts a temporary callback server on `127.0.0.1` and waits
@@ -55,6 +62,14 @@ containers, or locked-down networks where the browser can't reach the CLI's
55
62
  loopback address, use `--no-browser`: the CLI prints a login URL, you open it
56
63
  in any browser, and paste back the code it displays. No local server required.
57
64
 
65
+ Each picker can be pre-answered with a flag: `-i/--instance` (instance name),
66
+ `-w/--workspace` (workspace ID or name), `-b/--branch` (branch label), and
67
+ `-p/--profile` (profile name to save). An empty value (`""`) takes the
68
+ picker's default answer: `-w ""` skips workspace selection, `-b ""` skips and
69
+ uses the live branch, and `-p ""` uses the default profile name. With all four
70
+ set alongside `--no-browser`, the only input is pasting the code from the
71
+ browser — useful for scripted or remote setups.
72
+
58
73
  If you can't run `xano auth` at all, you can always create a profile manually
59
74
  with a Metadata API token from the Xano dashboard — see
60
75
  [Profiles](#profiles) below.
@@ -3,10 +3,14 @@ export default class Auth extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
7
  config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
8
  insecure: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
10
  'no-browser': import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
11
  origin: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
14
  };
11
15
  run(): Promise<void>;
12
16
  private getHeaders;
@@ -15,6 +19,9 @@ export default class Auth extends Command {
15
19
  private fetchWorkspaces;
16
20
  private promptForToken;
17
21
  private promptProfileName;
22
+ private resolveBranch;
23
+ private resolveInstance;
24
+ private resolveWorkspace;
18
25
  private saveProfile;
19
26
  private selectBranch;
20
27
  private selectInstance;
@@ -23,8 +23,15 @@ Opening browser for Xano login at https://custom.xano.com...`,
23
23
  To authenticate, open the following URL in any browser:
24
24
  https://app.xano.com/login?dest=cli&display=code
25
25
  ? Paste the code shown in your browser: ****`,
26
+ `$ xano auth --no-browser --instance my-instance --workspace 5 --branch dev --profile staging
27
+ (non-interactive: only the pasted code is prompted for)`,
26
28
  ];
27
29
  static flags = {
30
+ branch: Flags.string({
31
+ char: 'b',
32
+ description: 'Pre-select a branch by label (skips the branch picker); pass "" to skip and use the live branch',
33
+ required: false,
34
+ }),
28
35
  config: Flags.string({
29
36
  char: 'c',
30
37
  description: 'Path to credentials file (default: ~/.xano/credentials.yaml)',
@@ -36,6 +43,11 @@ To authenticate, open the following URL in any browser:
36
43
  default: false,
37
44
  description: 'Skip TLS certificate verification (for self-signed certificates)',
38
45
  }),
46
+ instance: Flags.string({
47
+ char: 'i',
48
+ description: 'Pre-select an instance by name (skips the instance picker)',
49
+ required: false,
50
+ }),
39
51
  'no-browser': Flags.boolean({
40
52
  default: false,
41
53
  description: 'Headless login: print a URL and paste back the code shown in the browser, instead of starting a local callback server (use on remote/SSH/Docker hosts where 127.0.0.1 is not reachable from the browser)',
@@ -45,6 +57,16 @@ To authenticate, open the following URL in any browser:
45
57
  default: 'https://app.xano.com',
46
58
  description: 'Xano account origin URL',
47
59
  }),
60
+ profile: Flags.string({
61
+ char: 'p',
62
+ description: 'Profile name to save (skips the profile name prompt); pass "" to use the default name',
63
+ required: false,
64
+ }),
65
+ workspace: Flags.string({
66
+ char: 'w',
67
+ description: 'Pre-select a workspace by ID or name (skips the workspace picker); pass "" to skip workspace',
68
+ required: false,
69
+ }),
48
70
  };
49
71
  async run() {
50
72
  const { flags } = await this.parse(Auth);
@@ -69,6 +91,9 @@ To authenticate, open the following URL in any browser:
69
91
  const isSelfHosted = !/^https:\/\/app\.(.*\.)?xano\.com$/.test(flags.origin);
70
92
  let instance;
71
93
  if (isSelfHosted) {
94
+ if (flags.instance) {
95
+ this.warn('Ignoring --instance: the origin itself is the instance for self-hosted Xano.');
96
+ }
72
97
  instance = {
73
98
  display: flags.origin,
74
99
  id: 'self-hosted',
@@ -83,7 +108,7 @@ To authenticate, open the following URL in any browser:
83
108
  if (instances.length === 0) {
84
109
  this.error('No instances found. Please check your account.');
85
110
  }
86
- instance = await this.selectInstance(instances);
111
+ instance = await this.resolveInstance(instances, flags.instance);
87
112
  }
88
113
  // Step 4: Workspace selection
89
114
  let workspace;
@@ -92,20 +117,25 @@ To authenticate, open the following URL in any browser:
92
117
  this.log('Fetching available workspaces...');
93
118
  const workspaces = await this.fetchWorkspaces(token, instance.origin);
94
119
  if (workspaces.length > 0) {
95
- workspace = await this.selectWorkspace(workspaces);
120
+ workspace = await this.resolveWorkspace(workspaces, flags.workspace);
96
121
  if (workspace) {
97
122
  // Step 5: Branch selection
98
123
  this.log('');
99
124
  this.log('Fetching available branches...');
100
125
  const branches = await this.fetchBranches(token, instance.origin, workspace.id);
101
- if (branches.length > 1) {
102
- branch = await this.selectBranch(branches);
103
- }
126
+ branch = await this.resolveBranch(branches, flags.branch);
104
127
  }
105
128
  }
129
+ else if (flags.workspace) {
130
+ this.error(`Workspace '${flags.workspace}' not found: no workspaces are available on this instance.`);
131
+ }
132
+ if (flags.branch && !workspace) {
133
+ this.warn('Ignoring --branch: no workspace selected.');
134
+ }
106
135
  // Step 6: Profile name
107
136
  this.log('');
108
- const profileName = await this.promptProfileName();
137
+ // An empty --profile value means "use the default name" (same as accepting the prompt's default)
138
+ const profileName = flags.profile === undefined ? await this.promptProfileName() : flags.profile.trim() || 'default';
109
139
  // Step 7: Save profile
110
140
  await this.saveProfile({
111
141
  access_token: token,
@@ -254,6 +284,49 @@ To authenticate, open the following URL in any browser:
254
284
  ]);
255
285
  return profileName.trim() || 'default';
256
286
  }
287
+ async resolveBranch(branches, flagValue) {
288
+ if (flagValue !== undefined) {
289
+ // An empty value means "skip and use live branch" (same as the picker's skip option)
290
+ if (flagValue.trim() === '') {
291
+ this.log('Using live branch');
292
+ return undefined;
293
+ }
294
+ const match = branches.find((br) => br.label === flagValue || br.id === flagValue);
295
+ if (!match) {
296
+ this.error(`Branch '${flagValue}' not found. Available branches: ${branches.map((br) => br.label).join(', ')}`);
297
+ }
298
+ this.log(`Using branch: ${match.label}`);
299
+ return match.id;
300
+ }
301
+ return branches.length > 1 ? this.selectBranch(branches) : undefined;
302
+ }
303
+ async resolveInstance(instances, flagValue) {
304
+ if (flagValue) {
305
+ const match = instances.find((inst) => inst.name === flagValue || inst.id === flagValue);
306
+ if (!match) {
307
+ this.error(`Instance '${flagValue}' not found. Available instances: ${instances.map((inst) => inst.name).join(', ')}`);
308
+ }
309
+ this.log(`Using instance: ${match.name} (${match.display})`);
310
+ return match;
311
+ }
312
+ return this.selectInstance(instances);
313
+ }
314
+ async resolveWorkspace(workspaces, flagValue) {
315
+ if (flagValue !== undefined) {
316
+ // An empty value means "skip workspace" (same as the picker's skip option)
317
+ if (flagValue.trim() === '') {
318
+ this.log('Skipping workspace selection');
319
+ return undefined;
320
+ }
321
+ const match = workspaces.find((ws) => String(ws.id) === flagValue || ws.name === flagValue);
322
+ if (!match) {
323
+ this.error(`Workspace '${flagValue}' not found. Available workspaces: ${workspaces.map((ws) => `${ws.name} (${ws.id})`).join(', ')}`);
324
+ }
325
+ this.log(`Using workspace: ${match.name} (${match.id})`);
326
+ return match;
327
+ }
328
+ return this.selectWorkspace(workspaces);
329
+ }
257
330
  async saveProfile(profile, configPath) {
258
331
  const credentialsPath = resolveCredentialsPath(configPath);
259
332
  const credDir = dirname(credentialsPath);