Skip to content

Comments

Agents group commands, and CLI help/auth#135

Closed
liranfarage89 wants to merge 17 commits intofeat/node-20-upgradefrom
feat/cli-agents-settings-list-agents
Closed

Agents group commands, and CLI help/auth#135
liranfarage89 wants to merge 17 commits intofeat/node-20-upgradefrom
feat/cli-agents-settings-list-agents

Conversation

@liranfarage89
Copy link

@liranfarage89 liranfarage89 commented Dec 3, 2025

Summary

This PR extends the @env0/cli with a new agents command, modernizes how commands and arguments are wired, and refreshes the help output and README to better reflect current behavior.

Key themes:

  • New agents command group with agents list.
  • Centralized command metadata (handlers, required options, help) in one place.
  • Credentials continue to work via all existing methods (configure/env/flags), with -k/-s on runtime commands now deprecated rather than removed.
  • Cleaner, more conventional --help output.
  • Updated README with clearer usage and structure.

Changes

1. New agents list command (Agents Settings API)

  • Added agents list CLI command to list organization agents, backed by the /agents API endpoint.

    • Usage:

      env0 agents list -o <organizationId>
  • Implementation:

    • Handler: src/commands/agents-settings-list-agents.js

      • Uses Env0ApiClient to call GET /agents with organizationId as a query param.
      • Logs the JSON response using the existing logger.
    • Command config in src/config/commands.js:

      'agents list': {
        handler: agentsSettingsListAgents,
        requiredOptions: ORG_REQUIRED_OPTIONS,   // apiKey, apiSecret, organizationId
        useDeployUtils: false,
        options: [argumentsMap[ORGANIZATION_ID]],
        help: [
          {
            desc: 'Lists organization agents',
            example: `$ env0 agents list -o <${ORGANIZATION_ID}>\n`
          }
        ]
      }
    • organizationId is grouped under agents in src/config/arguments.js so it appears correctly in help output.


2. Centralized command wiring & required options

  • Before: run-command.js hard‑coded per‑command handlers and required options.

  • After: src/config/commands.js is the single source of truth:

    Each command now has:

    • handler – function implementing the command.
    • requiredOptions – which options must be present.
    • useDeployUtils – whether to initialize DeployUtils.
    • options – CLI option schema for command-line-args.
    • help – description and example(s) used for --help.
  • src/commands/run-command.js is now generic:

    • Looks up commands[command] and uses the command’s requiredOptions / useDeployUtils / options instead of hard-coding.
    • Initializes DeployUtils only when useDeployUtils is true.
    • Calls commandConfig.handler(options, variables).

This makes adding new commands (including future agents <subcommand>s) primarily a matter of adding an entry in config/commands.js plus a handler module.


3. Auth flow: non-breaking, with deprecation warning

  • Goal: Improve auth UX by encouraging env0 configure and env vars, without breaking existing flows that rely on -k/-s.

  • Changes:

    • In src/config/arguments.js:

      • apiKey / apiSecret (API_KEY, API_SECRET) remain defined with secret: true and are still available to runtime commands via shared base arguments.
      • organizationId is also grouped under agents so it is exposed for agents list.
    • In src/config/commands.js:

      • Runtime commands (deploy, destroy, approve, cancel) once again use base argument sets that include apiKey / apiSecret, so -k/-s work as before.
      • agents list uses only organizationId as its explicit option, with credentials coming from configure/env/flags.
      • configure continues to expose -k/--apiKey and -s/--apiSecret for initial setup.
    • In src/main.js:

      • New warnOnDeprecatedCredentialFlags helper detects use of -k/--apiKey and -s/--apiSecret (and their =value forms) on non-configure commands.
      • When present, a yellow deprecation warning is logged, but the flags are still passed through to commandLineArgs and configManager.read as before.
      • No argv mutation: behavior is non‑breaking; this is a warning-only change.
    • In src/commands/help.js:

      • Help output hides any options whose schema has secret: true, so apiKey/apiSecret don’t show up under runtime commands, while remaining valid flags.
    • config-manager behavior remains the same:

      • Merge order is still: config file < env vars < CLI params.
      • Existing tests (tests/lib/config-manager.spec.js) already assert:
        • Env vars override config file.
        • CLI params override env vars + config.
  • README updates:

    • Clarifies that runtime commands can still accept apiKey / apiSecret flags for backwards compatibility, but these are now deprecated.
    • Encourages using env0 configure and/or ENV0_API_KEY / ENV0_API_SECRET going forward.

4. Grouped agents commands and routing

  • src/main.js now supports grouped commands for agents:

    • After handling internal commands (help/version/configure), any agents <subcommand> invocation is mapped:

      if (command === "agents" && argv.length > 0) {
        command = `agents ${argv[0]}`;
        argv = argv.slice(1);
      }
    • This currently supports:

      • env0 agents list -o <organizationId>
    • And will work for future subcommands like agents delete, agents update, etc., as long as they are defined in config/commands.js.

  • env0 agents --help is treated as an internal help call before remapping, so it shows a dedicated agents help page (see below) instead of trying to run a subcommand.


5. Help output improvements

  • File: src/commands/help.js

  • Top‑level help (env0 --help):

    • Now a more conventional layout:

      • Usageenv0 <command> [options].

      • Commands – only top‑level commands (deploy, destroy, approve, cancel, configure, version, help, agents).

        • agents is summarized as:

          agents   Manage agents (run `env0 agents --help` for subcommands)
          
      • Per-command ... options sections are rendered only for top-level commands (no spaces in name).

      • Examples – driven by each command’s help array from config/commands.js.

      • Footer with project URL.

  • Agents‑specific help (env0 agents --help):

    • Uses a separate layout built from commands entries that start with agents :

      • Usageenv0 agents <command> [options].

      • Commands – currently:

        agents list   Lists organization agents
        
      • agents list options – shows only organizationId.

      • Examples – only agents examples.

  • src/main.js passes the command into help(command) so:

    • env0 --help → top-level help.
    • env0 agents --help → agents‑specific help.

6. Tests

  • Existing tests for run-command, deploy, destroy, config-manager, etc., continue to validate behavior around required options and config/env precedence.

  • Given this PR is focused on behavior and compatibility rather than new core flows, the primary safeguards are the existing suite plus manual verification of:

    • env0 --help top-level layout.
    • env0 agents --help grouped agents help.
    • env0 agents list -o <org> with credentials coming from configure / env vars / -k/-s.

7. README refresh

  • File: node/README.md

  • Modernized and aligned with current behavior:

    • Documents:

      • Installation and usage.
      • Quick start (configuredeploy--help / agents --help).
      • Configuration & authentication, including precedence and the fact that runtime commands can still accept apiKey / apiSecret flags for backwards compatibility, but these flags are now deprecated and env0 configure / env vars are preferred.
      • Commands: deploy, destroy, approve, cancel, grouped agents commands (currently agents list), configure, version, help.
      • Arguments and environment variables.
      • Project structure (where to look to add new commands, especially grouped ones).
      • Development flow (install, test, lint, custom ENV0_API_URL).

Notes for reviewers

  • Backward compatibility:

    • All existing auth flows remain supported:
      • env0 configure.
      • ENV0_API_KEY / ENV0_API_SECRET env vars.
      • -k/-s flags on runtime commands, now accompanied by a deprecation warning instead of a behavior change.
    • Top‑level --help is more concise; detailed per‑subcommand help is available via env0 agents --help.
  • Extensibility:

    • New commands (especially under agents) can be added by:
      1. Adding an entry in src/config/commands.js (with handler, requiredOptions, useDeployUtils, options, help).
      2. Implementing the handler in src/commands/….
    • No changes are required in main.js or run-command.js for additional agents <subcommand> entries.

@liranfarage89 liranfarage89 changed the title Add agents-settings-list-agents CLI command Update Node Version to 18.x + agents command + refactoring Dec 3, 2025
@liranfarage89 liranfarage89 requested a review from a team December 3, 2025 16:18
Copy link
Contributor

@chpl chpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • node 18 is not supported anymore
  • changing auth method is breaking change - you should keep any existing configuration method
  • split into multiple PRs

@liranfarage89 liranfarage89 changed the base branch from master to feat/node-20-upgrade December 8, 2025 13:37
@liranfarage89 liranfarage89 changed the base branch from feat/node-20-upgrade to master December 8, 2025 13:46
@liranfarage89 liranfarage89 changed the base branch from master to feat/node-20-upgrade December 8, 2025 13:47
@liranfarage89
Copy link
Author

  • node 18 is not supported anymore
  • changing auth method is breaking change - you should keep any existing configuration method
  • split into multiple PRs

@chpl

Thanks for the review and the notes.

  1. Node version

    • Updated the CLI to require Node >= 20.
    • CI and publish workflows now use Node 20.x.
    • README now states “Requires Node 20+”.
  2. Auth behavior (no breaking change)

    • All existing auth methods remain supported:
      • env0 configure.
      • ENV0_API_KEY / ENV0_API_SECRET.
      • -k/--apiKey and -s/--apiSecret on runtime commands.
    • I added a yellow deprecation warning when -k/-s are used on non-configure commands, but I don’t strip or reject them, so existing scripts keep working.
    • Help output hides secret options so apiKey/apiSecret don’t show up under runtime commands, and the README encourages using configure/env going forward.
  3. PR size / future PRs

    • I’ve split out a separate Node 20 upgrade branch/PR so the version bump is isolated.
    • This PR now focuses on CLI behavior: auth deprecation warning, agents group/agents list, and help/README improvements.

@liranfarage89 liranfarage89 changed the title Update Node Version to 18.x + agents command + refactoring Update Node 20, agents group commands, and CLI help/auth Dec 8, 2025
@liranfarage89 liranfarage89 changed the title Update Node 20, agents group commands, and CLI help/auth Agents group commands, and CLI help/auth Dec 8, 2025
@liranfarage89 liranfarage89 requested a review from chpl December 8, 2025 15:59
Comment on lines +16 to +39
const DEPRECATED_CREDENTIAL_FLAGS = ['-k', '--apiKey', '-s', '--apiSecret'];

const warnOnDeprecatedCredentialFlags = (command, argv) => {
if (command === 'configure') return;

const hasDeprecatedFlag = argv.some(arg => {
if (DEPRECATED_CREDENTIAL_FLAGS.includes(arg)) return true;
return (
arg.startsWith('--apiKey=') ||
arg.startsWith('-k=') ||
arg.startsWith('--apiSecret=') ||
arg.startsWith('-s=')
);
});

if (hasDeprecatedFlag) {
const YELLOW = '\u001b[33m';
const RESET = '\u001b[0m';
logger.info(
`${YELLOW}Warning: -k/--apiKey and -s/--apiSecret are deprecated for this command and may be removed in a future version. Prefer using "env0 configure" or ENV0_API_KEY/ENV0_API_SECRET instead.${RESET}`
);
}
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why deprecate it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's bad practice to pass sensitive variables like that, isn't it?

Remove command prefix grouping logic from getCommandOptions and return parsed options directly. Export getCommandOptions for testing. Update test mocks to match new flat structure without command key nesting.
…g file

Update config merge order in config-manager to prioritize environment variables over CLI parameters. Add tests to verify env vars take precedence in both scenarios with and without config file. Add test coverage for agents-settings-list-agents command.
@liranfarage89
Copy link
Author

closing this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants