Skip to content

darinkishore/xmlapply

Repository files navigation

xmlapply

xmlapply is a command-line tool for applying file changes defined in an XML specification to a target project directory. It helps you create, update, or delete files based on XML instructions, often generated by tools like o1.

Installation

uv tool install xmlapply
pipx install xmlapply

Workflow

To get started, install code2prompt with:

cargo install code2prompt

Then clone this repository, navigate into it, and set up a place to store your templates:

git clone https://github.com/darinkishore/xmlapply.git
cd xmlapply
mkdir -p ~/templates
cp o1.hbs ~/templates/

When you want to use o1 to assist a project, go to the project directory and run:

xmlapply use-dir . 

This sets the current directory as the one xmlapply will work on. Then, for any directory you’d like to include as context (including the root .), do:

code2prompt --template ~/templates/o1.hbs <directory>

Provide that output to o1, copy the resulting XML to your clipboard, and finally apply the changes:

xmlapply apply

If you have no file specified, xmlapply will check your clipboard for XML content.

Features

XML-Defined Changes. You can specify file operations in XML, including create, update, or delete.
Clipboard Support. If no XML file is specified, xmlapply can read from your clipboard.
Configurable Default Directory. Set a default directory so you don’t have to specify it every time.
Dry-Run Mode. Preview changes without modifying any files.

How It Works

xmlapply parses an XML file (or clipboard content) to determine which files should be created, updated, or deleted. It applies those operations to your target directory and never modifies files outside that directory. A simple YAML config (~/.xmlapply.yml) tracks your default project directory if you choose to set one.

Installation

You’ll need Python 3.8+ and pip installed on your system. Then:

git clone https://github.com/yourusername/xmlapply.git
cd xmlapply
pip install .

This sets up xmlapply as a CLI command (ensure ~/.local/bin or equivalent is on your PATH).

Usage

Run:

xmlapply [COMMAND] [OPTIONS]

Use apply to apply changes from an XML file:

xmlapply apply --file /path/to/changes.xml --directory /path/to/project

If no --directory is provided, xmlapply uses your default directory. If no --file is provided, xmlapply looks for XML in your clipboard:

xmlapply apply

You can change your default directory via:

xmlapply set_dir /path/to/my/project

To view the current configuration:

xmlapply show_config

And to preview changes without applying them:

xmlapply apply --file changes.xml --dry-run

XML Format

xmlapply expects something like:

<root>
  <changed_files>
    <file>
      <file_summary>Initial creation of README</file_summary>
      <file_operation>CREATE</file_operation>
      <file_path>docs/README.md</file_path>
      <file_code>This is the README content</file_code>
    </file>
    <file>
      <file_summary>Remove obsolete config</file_summary>
      <file_operation>DELETE</file_operation>
      <file_path>config/old_config.yml</file_path>
    </file>
  </changed_files>
</root>

The required fields are <file_operation> (CREATE, UPDATE, or DELETE) and <file_path> (relative path within the project). Optional fields include <file_summary> for a description and <file_code> for file content.

Configuration

xmlapply stores configuration in a YAML file at ~/.xmlapply.yml. This file mainly contains the default_directory setting. Generally, you won’t need to edit this file by hand—use the set_dir command instead.

Examples

Apply from a file:

xmlapply apply --file test.xml --directory /Users/darin/Projects/myproject

Apply from clipboard to the default directory:

xmlapply apply

Preview without making changes:

xmlapply apply --file edge_cases.xml --dry-run

Credits

Inspired by the XML-handling approach used in o1-xml-parser.

Development

This repository includes a CLI tool (src/xmlapply/cli.py), an XML parser (src/xmlapply/parser.py), and an applier (src/xmlapply/apply.py). Configuration is handled by src/xmlapply/config.py, and the package interface is defined in src/xmlapply/__init__.py. Examples and tests are provided in test.xml and edge_cases.xml.

To set up your development environment, install dependencies:

pip install -r requirements.txt

Then run:

python hello.py

to confirm it’s working. You should see:

Hello from xmlapply!

License

This project is distributed under the terms of the MIT license. See LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors