Skip to content

feat: add --format dotenv output format#299

Open
jongio wants to merge 1 commit into
mainfrom
idea/format-dotenv
Open

feat: add --format dotenv output format#299
jongio wants to merge 1 commit into
mainfrom
idea/format-dotenv

Conversation

@jongio

@jongio jongio commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Closes #296

What

Adds --format dotenv, an output format that renders a JSON response as
KEY=value environment lines you can eval into a shell, feed to a CI job, or
save as a docker --env-file.

azd rest get https://management.azure.com/subscriptions/$SUB?api-version=2022-12-01 --format dotenv

How it works

  • Reuses flattenJSONBody so nested fields become dotted paths, then maps each
    path to an env-safe name: runs of non-alphanumeric characters collapse to a
    single underscore, the name is upper cased, and a leading digit is prefixed
    with _ so the identifier stays valid.
    • properties.state becomes PROPERTIES_STATE
    • value[0].name becomes VALUE_0_NAME
  • String values are emitted bare when they are already shell-safe and
    double-quoted with escaping otherwise. Numbers and booleans pass through as
    literals, and null becomes an empty value.
  • Keys are sorted so output is deterministic.
  • A response that is not a JSON object or array has no field names to emit, so
    it returns a clear error.

Lives entirely in the service layer next to the existing table, jsonl,
yaml, and csv renderers. No transport or auth changes.

Tests

format_dotenv_test.go covers flat objects, nested-to-dotted keys, array index
keys, top-level arrays, value quoting and escaping, safe bare strings,
deterministic ordering, and the non-JSON error path.

Docs

Updated the --format enumeration and added an example in the README, the web
reference, the CLI reference, and the skill doc.

Render a JSON response as KEY=value environment lines for a shell eval, a CI job, or a docker --env-file. Flattens nested fields to dotted paths, maps each to an env-safe uppercase name, and quotes values only when needed. Lives in the service layer alongside the table, jsonl, yaml, and csv renderers.

Closes #296

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 19, 2026
@jongio jongio self-assigned this Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview

Your PR preview is ready!

📎 Preview URL: https://jongio.github.io/azd-rest/pr/299/

This preview will be automatically cleaned up when the PR is closed.

github-actions Bot added a commit that referenced this pull request Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Test This PR

A preview build (0.5.0-pr299) is ready for testing!

One-Line Install (Recommended)

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.ps1) } -PrNumber 299 -Version 0.5.0-pr299"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 299 0.5.0-pr299

Uninstall

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 299"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 299

Build Info:

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

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a dotenv output format for shell and CI variables

1 participant