Skip to content

Replace json-output boolean with type string option#26

Merged
cryi merged 10 commits intomainfrom
copilot/replace-json-output-format
Jan 21, 2026
Merged

Replace json-output boolean with type string option#26
cryi merged 10 commits intomainfrom
copilot/replace-json-output-format

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 21, 2026

Replace the json-output boolean flag with a type string option accepting "hjson" or "json" values in the modify command.

Changes

  • Option definition (app.lua:186-190): Changed from ["json-output"] boolean to type string type with alias t
  • File option (app.lua:165-169): Added alias f for --file option for easier typing
  • Description: Updated to "Content type of file we are modifying (hjson or json)"
  • Validation (util.lua:227-231): Type validation moved to util.modify_file() for better separation of concerns
  • Parameter renamed to content_type: Both am.modify_file and util.modify_file now use content_type parameter instead of output_format to avoid shadowing the built-in type() function
  • Clean implementation: No closures or workarounds needed - simple parameter rename avoids any shadowing issues
  • Option filtering: Excluded type key from modification mode filter (set/unset/add/remove)
  • Parameter flow: Pass type value to am.modify_file() as fifth parameter
  • Test fix: Corrected file path issue in tests

Usage

# Before
ami modify --json-output config.key value

# After - full option names
ami modify --type=json config.key value
ami modify --type=hjson config.key value  # explicit hjson (default)

# After - using aliases
ami modify -t json config.key value
ami modify -f myfile.json -t json server.port 8080

Default remains hjson when type is unspecified. Invalid values like --type=xml error with: "type must be either 'hjson' or 'json'" (validation performed in util.modify_file).

Original prompt

On app.lua:185-185, Replace json output with a format option accepting string - either hjson or json.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace json output with format option for hjson or json Replace json-output boolean with format string option Jan 21, 2026
Copilot AI requested a review from cryi January 21, 2026 05:18
@cryi
Copy link
Copy Markdown
Contributor

cryi commented Jan 21, 2026

@copilot Move format validation into util modify_file. Update modify file functions to actually use format. Make sure that util.modify file defaults to hjson if no format specified. Alias --file in case od modify to f so it is easier to type. Amd actually chanbe format in modify to type aliased to t. Description should say it is content type of file we are modifying.

Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot Move format validation into util modify_file. Update modify file functions to actually use format. Make sure that util.modify file defaults to hjson if no format specified. Alias --file in ca...

Done in commit 22053e2:

  • ✅ Moved format validation to util.modify_file (lines 227-230)
  • ✅ Format is being used on line 267 to select stringify function
  • ✅ util.modify_file defaults to hjson (line 225)
  • ✅ Added alias 'f' for --file option
  • ✅ Added alias 't' for format option
  • ✅ Updated description to "Content type of file we are modifying (hjson or json)"

@cryi
Copy link
Copy Markdown
Contributor

cryi commented Jan 21, 2026

@copilot Nah drop format option and replace it eith type. I want to type --type only. And output format is supposed to be replaced with type in both instance of modify_file so it is consistant.

Copilot AI and others added 2 commits January 21, 2026 05:37
Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot Nah drop format option and replace it eith type. I want to type --type only. And output format is supposed to be replaced with type in both instance of modify_file so it is consistant.

Done in commits 038aae8 and 3b9940d:

  • ✅ Dropped format option and replaced with type option
  • ✅ Renamed output_format parameter to type in both am.modify_file and util.modify_file
  • ✅ Saved reference to built-in type() function as _type to avoid shadowing in both functions
  • ✅ Updated error message to "type must be either 'hjson' or 'json'"
  • ✅ Updated all tests to use --type instead of --format

Users can now use --type or -t to specify the content type.

Copilot AI changed the title Replace json-output boolean with format string option Replace json-output boolean with type string option Jan 21, 2026
@cryi
Copy link
Copy Markdown
Contributor

cryi commented Jan 21, 2026

@copilot I dont like tackling with _G. Cant we do it more elegantly?

Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot I dont like tackling with _G. Cant we do it more elegantly?

Done in commit b7278e7. Replaced _G.type with a cleaner do-end closure that captures the built-in type function as typeof before the parameter shadows it. This is more idiomatic Lua and avoids directly accessing _G.

Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
@cryi
Copy link
Copy Markdown
Contributor

cryi commented Jan 21, 2026

@copilot Just rename type argument to functions to content type. That way we dont have to use do or _G. We can still keep it as --type in args. That wont interfere. And fix the tst

Co-authored-by: cryi <36897290+cryi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot Just rename type argument to functions to content type. That way we dont have to use do or _G. We can still keep it as --type in args. That wont interfere. And fix the tst

Done in commit e8e3132:

  • ✅ Renamed type parameter to content_type in both am.modify_file and util.modify_file
  • ✅ Removed do-end closures - no longer needed
  • ✅ CLI option remains --type (or -t alias)
  • ✅ Fixed test file path issue that was causing failures

@cryi cryi marked this pull request as ready for review January 21, 2026 13:30
@cryi cryi merged commit bd4292a into main Jan 21, 2026
1 check passed
cryi added a commit that referenced this pull request Jan 21, 2026
Modify with support for json output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants