From d9446cf0c72f4db3b9e125dc64bc9429e7e7391a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:48:23 +0000 Subject: [PATCH 1/4] Initial plan From 4b8f0e4cc5467df106b13353c1c6ccf33c0c87e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:55:45 +0000 Subject: [PATCH 2/4] feat: add scale support to get command YAML config Agent-Logs-Url: https://github.com/cherrybit-studios/pepper_sprite_cli/sessions/8a4d3e80-7eb0-43b3-8e2c-515d2b674c53 Co-authored-by: erickzanardo <835641+erickzanardo@users.noreply.github.com> --- lib/src/commands/get_command.dart | 54 ++++++++++- test/src/commands/get_command_test.dart | 117 ++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 5 deletions(-) diff --git a/lib/src/commands/get_command.dart b/lib/src/commands/get_command.dart index 5fa0294..a680456 100644 --- a/lib/src/commands/get_command.dart +++ b/lib/src/commands/get_command.dart @@ -10,13 +10,16 @@ import 'package:yaml/yaml.dart'; /// Configuration for a single file to download and export class FileConfig { /// Creates a file config - FileConfig({required this.fileId, required this.output}); + FileConfig({required this.fileId, required this.output, this.scale}); /// The file ID to download final String fileId; /// The output path for the exported image final String output; + + /// Optional scale dimensions in WIDTH,HEIGHT format (e.g. "512,512") + final String? scale; } /// {@template get_command} @@ -116,9 +119,10 @@ class GetCommand extends Command { final fileId = fileMap['fileId'] as String?; final output = fileMap['output'] as String?; + final scale = fileMap['scale'] as String?; if (fileId != null && output != null) { - configs.add(FileConfig(fileId: fileId, output: output)); + configs.add(FileConfig(fileId: fileId, output: output, scale: scale)); } } @@ -130,6 +134,31 @@ class GetCommand extends Command { Future _processFile(FileConfig config, String apiKey) async { _logger.info('Processing ${config.fileId}...'); + // Validate and parse scale if provided + int? scaleWidth; + int? scaleHeight; + if (config.scale != null) { + final parts = config.scale!.split(','); + if (parts.length != 2) { + _logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ); + return false; + } + final w = int.tryParse(parts[0]); + final h = int.tryParse(parts[1]); + if (w == null || h == null || w <= 0 || h <= 0) { + _logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ); + return false; + } + scaleWidth = w; + scaleHeight = h; + } + // Create temp file final tempDir = Directory.systemTemp.createTempSync('pepper_sprite_'); final tempFile = File(path.join(tempDir.path, '${config.fileId}.psp')); @@ -146,7 +175,12 @@ class GetCommand extends Command { } // Export file - await _exportFile(tempFile, config.output); + await _exportFile( + tempFile, + config.output, + scaleWidth: scaleWidth, + scaleHeight: scaleHeight, + ); _logger.success(' Exported to ${config.output}'); return true; @@ -187,7 +221,12 @@ class GetCommand extends Command { } /// Exports a PSP file to PNG - Future _exportFile(File sourceFile, String outputPath) async { + Future _exportFile( + File sourceFile, + String outputPath, { + int? scaleWidth, + int? scaleHeight, + }) async { final bytes = await sourceFile.readAsBytes(); // Deserialize @@ -205,6 +244,11 @@ class GetCommand extends Command { } // Export - ImageExporter.exportToPngFile(file, outputPath); + ImageExporter.exportToPngFile( + file, + outputPath, + scaleWidth: scaleWidth, + scaleHeight: scaleHeight, + ); } } diff --git a/test/src/commands/get_command_test.dart b/test/src/commands/get_command_test.dart index ad5bef1..bc1ba7f 100644 --- a/test/src/commands/get_command_test.dart +++ b/test/src/commands/get_command_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pepper_sprite_cli/src/command_runner.dart'; @@ -35,5 +37,120 @@ void main() { // and the get command is registered expect(commandRunner, isNotNull); }); + + group('scale', () { + late Directory tempDir; + late File configFile; + + setUp(() { + tempDir = Directory.systemTemp.createTempSync('pepper_sprite_test_'); + configFile = File('${tempDir.path}/pepper-sprite.yaml'); + }); + + tearDown(() { + tempDir.deleteSync(recursive: true); + }); + + test('invalid format — non-numeric', () async { + configFile.writeAsStringSync(''' +files: + - fileId: "test-id" + output: "/tmp/output.png" + scale: "abc,def" +'''); + + final exitCode = await commandRunner.run([ + 'get', + '-k', + 'test-api-key', + '-c', + configFile.path, + ]); + + expect(exitCode, ExitCode.software.code); + verify( + () => logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ), + ).called(1); + }); + + test('invalid format — single value', () async { + configFile.writeAsStringSync(''' +files: + - fileId: "test-id" + output: "/tmp/output.png" + scale: "512" +'''); + + final exitCode = await commandRunner.run([ + 'get', + '-k', + 'test-api-key', + '-c', + configFile.path, + ]); + + expect(exitCode, ExitCode.software.code); + verify( + () => logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ), + ).called(1); + }); + + test('invalid format — zero width', () async { + configFile.writeAsStringSync(''' +files: + - fileId: "test-id" + output: "/tmp/output.png" + scale: "0,512" +'''); + + final exitCode = await commandRunner.run([ + 'get', + '-k', + 'test-api-key', + '-c', + configFile.path, + ]); + + expect(exitCode, ExitCode.software.code); + verify( + () => logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ), + ).called(1); + }); + + test('invalid format — negative height', () async { + configFile.writeAsStringSync(''' +files: + - fileId: "test-id" + output: "/tmp/output.png" + scale: "512,-1" +'''); + + final exitCode = await commandRunner.run([ + 'get', + '-k', + 'test-api-key', + '-c', + configFile.path, + ]); + + expect(exitCode, ExitCode.software.code); + verify( + () => logger.err( + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512', + ), + ).called(1); + }); + }); }); } + From 874bb991cf9afedeb29a1c926fc1d4fa2b6e74b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:57:11 +0000 Subject: [PATCH 3/4] fix: trim whitespace from scale parts and remove trailing blank line Agent-Logs-Url: https://github.com/cherrybit-studios/pepper_sprite_cli/sessions/8a4d3e80-7eb0-43b3-8e2c-515d2b674c53 Co-authored-by: erickzanardo <835641+erickzanardo@users.noreply.github.com> --- lib/src/commands/get_command.dart | 2 +- test/src/commands/get_command_test.dart | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/commands/get_command.dart b/lib/src/commands/get_command.dart index a680456..ebf704e 100644 --- a/lib/src/commands/get_command.dart +++ b/lib/src/commands/get_command.dart @@ -138,7 +138,7 @@ class GetCommand extends Command { int? scaleWidth; int? scaleHeight; if (config.scale != null) { - final parts = config.scale!.split(','); + final parts = config.scale!.split(',').map((e) => e.trim()).toList(); if (parts.length != 2) { _logger.err( ' scale must be in the format WIDTH,HEIGHT with positive ' diff --git a/test/src/commands/get_command_test.dart b/test/src/commands/get_command_test.dart index bc1ba7f..f9f5b00 100644 --- a/test/src/commands/get_command_test.dart +++ b/test/src/commands/get_command_test.dart @@ -153,4 +153,3 @@ files: }); }); } - From 779668ad5566df16e36fb49b2678c43678c91ab9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:58:05 +0000 Subject: [PATCH 4/4] refactor: extract duplicated scale error message into constant Agent-Logs-Url: https://github.com/cherrybit-studios/pepper_sprite_cli/sessions/8a4d3e80-7eb0-43b3-8e2c-515d2b674c53 Co-authored-by: erickzanardo <835641+erickzanardo@users.noreply.github.com> --- lib/src/commands/get_command.dart | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/src/commands/get_command.dart b/lib/src/commands/get_command.dart index ebf704e..5e14306 100644 --- a/lib/src/commands/get_command.dart +++ b/lib/src/commands/get_command.dart @@ -138,21 +138,18 @@ class GetCommand extends Command { int? scaleWidth; int? scaleHeight; if (config.scale != null) { + const scaleFormatError = + ' scale must be in the format WIDTH,HEIGHT with positive ' + 'integers, e.g. 512,512'; final parts = config.scale!.split(',').map((e) => e.trim()).toList(); if (parts.length != 2) { - _logger.err( - ' scale must be in the format WIDTH,HEIGHT with positive ' - 'integers, e.g. 512,512', - ); + _logger.err(scaleFormatError); return false; } final w = int.tryParse(parts[0]); final h = int.tryParse(parts[1]); if (w == null || h == null || w <= 0 || h <= 0) { - _logger.err( - ' scale must be in the format WIDTH,HEIGHT with positive ' - 'integers, e.g. 512,512', - ); + _logger.err(scaleFormatError); return false; } scaleWidth = w;