Skip to content

Comments

feat: Add --options-file json patch/option configuration#53

Merged
LisoUseInAIKyrios merged 10 commits intoMorpheApp:devfrom
prateek-who:export-json
Feb 19, 2026
Merged

feat: Add --options-file json patch/option configuration#53
LisoUseInAIKyrios merged 10 commits intoMorpheApp:devfrom
prateek-who:export-json

Conversation

@prateek-who
Copy link
Contributor

@prateek-who prateek-who commented Feb 16, 2026

Allows users to export a patch.mpp file's patches and its options to a json file. What's new:

  1. New options-create subcommand:
    Exports all patches from the patch.mpp file into a json file with:
    java -jar morphe-cli-all.jar options-create --patches patches.mpp --output options.json
    this exports all patches, use -f flag for filtering the patches for the app you need.

  2. New --options-file flag on the patch command:
    Allow users to use the json file to suggest what patches they want/ don't want to the cli.
    java -jar morphe-cli-all.jar patch --patches patches-1.13.0.mpp --options-file options.json --output patched.apk input.apk

  3. New --skip-options-update flag on the patch command
    By default, after patching, the JSON file is auto-updated to stay in sync with the patch.mpp:

    • New patches added to .mpp get appended with defaults
    • Patches removed from .mpp get dropped
    • New option keys get added, stale ones removed
    • Your existing enabled values and option edits are preserved
       
      If you don't want to update the options.json file, add --skip-options-update argument.

allows users to export a patch.mpp file's patches and its options to a json file.
@prateek-who
Copy link
Contributor Author

Please check this thoroughly once. I used a lot of claude to write this. Even though it seems to work in my testing, check the code quality once and if it is following your standards of the project.

Create the options.json file by default when not present and start patching using default options. Says it in the logs too
@prateek-who
Copy link
Contributor Author

try this once

@LisoUseInAIKyrios
Copy link
Contributor

Everything seems to be working. This is a big improvement from the old xargs nonsense that was previously required.

@LisoUseInAIKyrios LisoUseInAIKyrios changed the title feat: patch-json update feat: Add --options-file json patch/option configuration Feb 17, 2026
@LisoUseInAIKyrios
Copy link
Contributor

When patching with the option-file argument, can the updated options.json be wrote to disk earlier? Right now it waits until all patching is done, but it would be more convenient if it updated the file immediately.

But if this behavior is difficult to add or adds to much complexity to the code then we should not make this change.

@wchill
Copy link
Contributor

wchill commented Feb 17, 2026

New --skip-options-update flag on the patch command
By default, after patching, the JSON file is auto-updated to stay in sync with the patch.mpp:

I think the behavior of this flag should be reversed, for safety reasons. It's not hard to envision situations where this might result in data loss. It should either be an explicit opt-in, or the CLI should generate a new timestamped JSON that the user can load next time if it notices that the patch options have changed.

@LisoUseInAIKyrios
Copy link
Contributor

New --skip-options-update flag on the patch command
By default, after patching, the JSON file is auto-updated to stay in sync with the patch.mpp:

I think the behavior of this flag should be reversed, for safety reasons. It's not hard to envision situations where this might result in data loss. It should either be an explicit opt-in, or the CLI should generate a new timestamped JSON that the user can load next time if it notices that the patch options have changed.

That makes sense. Can invert the logic and change it to --options-update

@prateek-who
Copy link
Contributor Author

Will make it so that it adds the timestamp too like: options_{timestamp}.json

Also, should we generate 2 files like options.json and patches.json as the issue author suggested? Does it have more benefits than our current system?

@LisoUseInAIKyrios
Copy link
Contributor

LisoUseInAIKyrios commented Feb 17, 2026

I think a timestamp in the file name makes it slightly less convenient because it's a weird file name and not the name the CLI command specified. At least for me I would immediately rename it to what I wanted so it's a second step.

How about timestamps inside the json?

It can be the first fields. Stuff like "created_at" : "18 February 2026, whatever time"
Another field for update date. Another field for input jar. Can add any other useful meta data if any exists.

@LisoUseInAIKyrios
Copy link
Contributor

I think a single JSON is ok. I'm not sure what useful situation two files would provide, especially since options are rarely the same between different patch repos.

@prateek-who
Copy link
Contributor Author

prateek-who commented Feb 17, 2026

Now if we reverse that flag, when the user doesn't use the flag the updation doesn't happen right? But if they do use that flag, do we overwrite the file?

@LisoUseInAIKyrios
Copy link
Contributor

LisoUseInAIKyrios commented Feb 17, 2026

If they use --options-update when patching then the the json file is updated (same behavior as before, remove unused patches/options and add missing patches/options).

If they don't use --options-update then the json file is never changed (even if it has outdated patches/JSON).

@prateek-who
Copy link
Contributor Author

See if this does the trick. Also currently the json updates once the apk is patched and written to disk. Should we maybe update the json file before the patching process begins?

@LisoUseInAIKyrios
Copy link
Contributor

Yes, I think that's the last change.

@wchill
Copy link
Contributor

wchill commented Feb 17, 2026

Now if we reverse that flag, when the user doesn't use the flag the updation doesn't happen right? But if they do use that flag, do we overwrite the file?

Give them a warning that their options JSON is out of date if (a) they don't provide the flag, and (b) the available options really did change.

That way, they know to use the flag and don't forget.

@prateek-who
Copy link
Contributor Author

Once issue we have right now is:
options-create: Nukes everything, fresh defaults. User loses all their choices.
--options-update (during patch): Merges and preserves user choices, adds new patches with defaults, drops removed ones.

What we don't have is, there's no way to do a merge without patching. If the user gets a new .mpp and just wants to see "what's new?", they either nuke their file with options-create or they have to run a full patch with --options-update.

So to solve this, we could simple let options-create do a merge too instead of remove and recreate the file? Add a --force flag to nuke and recreate the json file if they want to. And then ofc move the joson updation of --options-update to happen before the patching starts. This will cover almost all edge cases but is it even necessary is the question? What do you think of this?

@wchill
Copy link
Contributor

wchill commented Feb 17, 2026

I think having options-create and --options-update might be a bit too extra. Maybe instead of options-create, add a new flag --dry-run which does the options merging and shows what patch options would have been selected (and exports the file), but doesn't actually patch/sign/install.

@LisoUseInAIKyrios
Copy link
Contributor

To prevent nuking, the existing options-create can update an existing json if the specified file exists. Otherwise it creates from new. So if they use the command with an existing options.json then the behavior is identical to using an option JSON during patching with the update option. I think this behavior is the most consistent and also will prevent data loss of the still relevant data.

So if the user wants to completely reset their options.json file, they would manually need to delete it before they run options-create. This command should be verbose in what's happening ("created new file", "updated file", etc).

@LisoUseInAIKyrios
Copy link
Contributor

LisoUseInAIKyrios commented Feb 17, 2026

I think having options-create and --options-update might be a bit too extra. Maybe instead of options-create, add a new flag --dry-run which does the options merging and shows what patch options would have been selected (and exports the file), but doesn't actually patch/sign/install.

I'm thinking do both operations in a single command. Create if the file isn't present, and update if it is.

Then there will be just 3 JSON CLI commands/arguments, and it handles all use cases. If a user wants to nuke their options and start over then they can manually delete it and create again.

@wchill
Copy link
Contributor

wchill commented Feb 17, 2026

Name it dump-options instead of options-create, maybe?

@LisoUseInAIKyrios
Copy link
Contributor

LisoUseInAIKyrios commented Feb 17, 2026

Name it dump-options instead of options-create, maybe?

Hmm, if it's updating then dump isn't quite right. But the existing options-create isn't right either because it can also update.

@prateek-who
Copy link
Contributor Author

To prevent nuking, the existing options-create can update an existing json if the specified file exists. Otherwise it creates from new. So if they use the command with an existing options.json then the behavior is identical to using an option JSON during patching with the update option. I think this behavior is the most consistent and also will prevent data loss of the still relevant data.

So if the user wants to completely reset their options.json file, they would manually need to delete it before they run options-create. This command should be verbose in what's happening ("created new file", "updated file", etc).

This feels like the best option.

Users now get a warning if their optisn.json file has differences with the patch.mpp file when using --options-file without --options-update.
CLI flags overriding JSON values now logs the information.
options-create now merges instead of deleting the entire file. Users can still create a completely new file by deleteing or renaming the old or the new file.
Potential memory leak fix by moving heavy patches (Set<Patch<*>> with DEX classloaders) inside the try block. The finally block now uses a lightweight patchesSnapshot (PatchOptionsFile) instead.
@prateek-who
Copy link
Contributor Author

Name it dump-options instead of options-create, maybe?

Hmm, if it's updating then dump isn't quite right. But the existing options-create isn't right either because it can also update.

I've left it as options-create as of right now, but will change it once somebody comes up with a better name

@LisoUseInAIKyrios
Copy link
Contributor

I think options-create is ok.

Updating is technically creation for most cases, and it accurately conveys the command as the starting point of JSON usage which is important.

Now the patches are checked against the target app making sure no extra patch throws new update warning
@LisoUseInAIKyrios LisoUseInAIKyrios merged commit 44943da into MorpheApp:dev Feb 19, 2026
1 check passed
github-actions bot pushed a commit that referenced this pull request Feb 19, 2026
# [1.4.0-dev.6](v1.4.0-dev.5...v1.4.0-dev.6) (2026-02-19)

### Features

* Add `--options-file` json patch/option configuration ([#53](#53)) ([44943da](44943da))
github-actions bot pushed a commit that referenced this pull request Feb 21, 2026
# [1.4.0](v1.3.0...v1.4.0) (2026-02-21)

### Bug Fixes

* Allow enabling/disabling patches using case insensitive patch names ([#48](#48)) ([03a280a](03a280a))
* Do not log patch name more than once if disabled ([#49](#49)) ([b980bb8](b980bb8))

### Features

* Add `--continue-on-error` argument, return non zero exit code if patching fails ([#47](#47)) ([255646b](255646b))
* Add `--options-file` json patch/option configuration ([#53](#53)) ([44943da](44943da))
* Add `--striplibs` argument to strip unwanted architectures ([#46](#46)) ([7442d94](7442d94))
* Support patching APKM bundles ([#40](#40)) ([bfe43d0](bfe43d0))
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.

feat: Create cli options to export both patches and options to JSON and set options from JSON during pathing

3 participants