Skip to content

Commit f6931cf

Browse files
committed
src: correctly use --outdir in src and readme
Signed-off-by: ChaoLiu <[email protected]>
1 parent cf5769c commit f6931cf

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

splitpatch/cli.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setup_args() -> argparse.Namespace:
2929

3030
# Base parameters
3131
parser.add_argument('patch_files', type=str, nargs='+', help='Input patch file paths, multiple files can be specified')
32-
parser.add_argument('--out-dir', type=str, help='Output directory path')
32+
parser.add_argument('--outdir', type=str, help='Output directory path')
3333

3434
# Split parameters
3535
parser.add_argument('--level', type=int, default=1, help='Merge level limit (default: 1)')
@@ -45,8 +45,8 @@ def setup_args() -> argparse.Namespace:
4545

4646
args = parser.parse_args()
4747
# Validate arguments
48-
if not args.dry_run and not args.out_dir:
49-
parser.error("--out-dir is required in non-dry-run mode")
48+
if not args.dry_run and not args.outdir:
49+
parser.error("--outdir is required in non-dry-run mode")
5050

5151
# Configure logging
5252
setup_logging(args.log_level)
@@ -55,8 +55,8 @@ def setup_args() -> argparse.Namespace:
5555
# Print argument information
5656
logger.info("Current arguments:")
5757
logger.info(f" Input files: {', '.join(args.patch_files)}")
58-
if args.out_dir:
59-
logger.info(f" Output directory: {args.out_dir}")
58+
if args.outdir:
59+
logger.info(f" Output directory: {args.outdir}")
6060
logger.info(f" Merge level: {args.level}")
6161
logger.info(f" File count threshold: {args.threshold}")
6262
logger.info(f" Log level: {args.log_level}")
@@ -133,12 +133,12 @@ def split_patch(patch: Patch, level: int, threshold: int) -> List[Patch]:
133133
return root.to_patches()
134134

135135

136-
def output_patches(patches: List[Patch], out_dir: str, dry_run: bool) -> None:
136+
def output_patches(patches: List[Patch], outdir: str, dry_run: bool) -> None:
137137
"""Output processed patches to specified directory
138138
139139
Args:
140140
patches: List of patches to output
141-
out_dir: Output directory path
141+
outdir: Output directory path
142142
dry_run: If True, only print info without actually writing files
143143
"""
144144
if dry_run:
@@ -148,10 +148,10 @@ def output_patches(patches: List[Patch], out_dir: str, dry_run: bool) -> None:
148148
logger.info(f"Patch {i:03d}_{normalized_path}.patch")
149149
return
150150

151-
os.makedirs(out_dir, exist_ok=True)
151+
os.makedirs(outdir, exist_ok=True)
152152
for i, patch in enumerate(patches, 1):
153153
normalized_path = patch.path.lstrip('/').replace('/', '_')
154-
output_file = os.path.join(out_dir, f"{i:03d}_{normalized_path}.patch")
154+
output_file = os.path.join(outdir, f"{i:03d}_{normalized_path}.patch")
155155

156156
try:
157157
patch.path = output_file
@@ -174,7 +174,7 @@ def main() -> None:
174174
patches = split_patch(combined_patch, args.level, args.threshold)
175175

176176
# Output results
177-
output_patches(patches, args.out_dir, args.dry_run)
177+
output_patches(patches, args.outdir, args.dry_run)
178178

179179
except Exception as e:
180180
logger.error(f"An error occurred during processing: {e}")

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def tearDown(self):
4242
os.remove(self.sample_patch_file)
4343
os.rmdir(self.temp_dir)
4444

45-
@patch('sys.argv', ['splitpatch', 'test.patch', '--out-dir', 'output', '--log-level', 'DEBUG'])
45+
@patch('sys.argv', ['splitpatch', 'test.patch', '--outdir', 'output', '--log-level', 'DEBUG'])
4646
def test_setup_args(self):
4747
"""Test command line argument parsing"""
4848
args = setup_args()
4949
self.assertEqual(args.patch_files, ['test.patch'])
50-
self.assertEqual(args.out_dir, 'output')
50+
self.assertEqual(args.outdir, 'output')
5151
self.assertEqual(args.log_level, 'DEBUG')
5252
self.assertEqual(args.level, 1) # Default value
5353
self.assertEqual(args.threshold, 10) # Default value
@@ -149,7 +149,7 @@ def test_main_function(self, mock_output, mock_split, mock_parse, mock_setup):
149149
# Mock command line arguments
150150
args = MagicMock()
151151
args.patch_files = [self.sample_patch_file]
152-
args.out_dir = "output"
152+
args.outdir = "output"
153153
args.level = 1
154154
args.threshold = 10
155155
args.dry_run = False

0 commit comments

Comments
 (0)