Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gptdiff/gptdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,12 @@ def parse_arguments():
parser.add_argument('--nowarn', action='store_true', help='Disable large token warning')
parser.add_argument('--anthropic_budget_tokens', type=int, default=None, help='Budget tokens for Anthropic extended thinking')
parser.add_argument('--verbose', action='store_true', help='Enable verbose output with detailed information')
return parser.parse_args()

# Allow optional arguments like --apply to appear before or after file paths
parse_fn = parser.parse_args
if hasattr(parser, 'parse_intermixed_args'):
parse_fn = parser.parse_intermixed_args
return parse_fn()

def absolute_to_relative(absolute_path):
cwd = os.getcwd()
Expand Down
21 changes: 21 additions & 0 deletions tests/test_argparse_interleaving.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
from unittest import mock

import gptdiff.gptdiff as gptdiff


def parse(argv):
with mock.patch.object(sys, 'argv', argv):
return gptdiff.parse_arguments()


def test_apply_after_file():
args = parse(['gptdiff', 'prompt', 'file.js', '--apply'])
assert args.apply is True
assert args.files == ['file.js']


def test_apply_before_file():
args = parse(['gptdiff', 'prompt', '--apply', 'file.js'])
assert args.apply is True
assert args.files == ['file.js']