@vatio-ai/cli 0.53.0 → 0.54.0

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/lib/support.mjs CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  import { execFileSync } from "node:child_process";
5
5
 
6
+ import { branchEnvironment } from "./branch.mjs";
7
+
6
8
  export class UserError extends Error {
7
9
  constructor(message) {
8
10
  super(message);
@@ -16,15 +18,17 @@ export function fail(message) {
16
18
  throw new UserError(message);
17
19
  }
18
20
 
19
- // `--env NAME` is the one way to say which deployment a command is about:
20
- // live, preview, or a named preview like pr-42.
21
+ // `--env NAME` is the one way to say which environment a command is about:
22
+ // live, preview, or a branch's own like fix-pagos.
21
23
  //
22
- // The default is the command's own and is passed in, because the sensible
23
- // answer differs: push writes a preview, pull brings down whatever is actually
24
- // running. `--as` was the spelling on push and publish and stays as an alias --
25
- // it is sitting in CI jobs, and there is nothing wrong with what it does.
26
- export function takeEnv(args, { fallback = null } = {}) {
27
- let environment = fallback;
24
+ // Without it, a workspace checked out on a branch other than the default one
25
+ // means that branch's environment (see branch.mjs), said once on stderr so it
26
+ // is never a surprise. Otherwise the default is the command's own and is passed
27
+ // in, because the sensible answer differs: push writes a preview, tokens are
28
+ // for live. `--as` was the spelling on push and publish and stays as an alias
29
+ // -- it is sitting in CI jobs, and there is nothing wrong with what it does.
30
+ export function takeEnv(args, { fallback = null, cwd = null } = {}) {
31
+ let environment;
28
32
  const rest = [];
29
33
 
30
34
  for (let i = 0; i < args.length; i += 1) {
@@ -39,13 +43,22 @@ export function takeEnv(args, { fallback = null } = {}) {
39
43
  continue;
40
44
  }
41
45
  i += 1;
42
- if (i >= args.length) fail(`${match[0]} needs a deployment name (live, preview, or a preview name)`);
46
+ if (i >= args.length) fail(`${match[0]} needs an environment name (live, preview, or a branch's)`);
43
47
  environment = args[i];
44
48
  }
45
49
 
46
50
  args.length = 0;
47
51
  args.push(...rest);
48
- return environment;
52
+ return environment !== undefined ? environment : branchDefault(cwd, fallback);
53
+ }
54
+
55
+ // The branch's environment when the workspace is on one, else `fallback`.
56
+ export function branchDefault(cwd, fallback) {
57
+ const fromBranch = cwd ? branchEnvironment(cwd) : null;
58
+ if (!fromBranch) return fallback;
59
+
60
+ process.stderr.write(paint("cyan", `vatio: environment ${fromBranch.environment} (branch ${fromBranch.branch})`) + "\n");
61
+ return fromBranch.environment;
49
62
  }
50
63
 
51
64
  export function takeFlag(args, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.53.0",
3
+ "version": "0.54.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",