The CLI is a mode of anm2ed (anm2ed info|frame|render ...), not a separate binary
On Windows it attaches to the console it was started from, and gets UTF-8 arguments like the editor does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2dbbfa5e86
commit
abb9f965d6
5 files changed
+51
-26
No files matched your search
+3
-7
@@ -111,7 +111,7 @@ foreach(CORE_FILE log resource/image resource/audio_data resource/asset_store ut
|
|||||||
util/pack util/imgui/multiselect snapshots playback selection)
|
util/pack util/imgui/multiselect snapshots playback selection)
|
||||||
list(APPEND CORE_SRC ${CORE_DIR}/${CORE_FILE}.cpp)
|
list(APPEND CORE_SRC ${CORE_DIR}/${CORE_FILE}.cpp)
|
||||||
endforeach()
|
endforeach()
|
||||||
list(REMOVE_ITEM PROJECT_SRC ${CORE_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/cli.cpp)
|
list(REMOVE_ITEM PROJECT_SRC ${CORE_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
|
||||||
|
|
||||||
set(CORE_INCLUDE_DIRS
|
set(CORE_INCLUDE_DIRS
|
||||||
include
|
include
|
||||||
@@ -136,10 +136,9 @@ if(NOT MSVC)
|
|||||||
target_compile_options(anm2ed_core PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(anm2ed_core PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# The editor's code as a library, shared by the editor, the CLI and the render tests.
|
# The editor's code as a library, shared by the editor and the render tests.
|
||||||
add_library(anm2ed_app STATIC ${GLAD_SRC} ${IMGUI_SRC} ${PROJECT_SRC})
|
add_library(anm2ed_app STATIC ${GLAD_SRC} ${IMGUI_SRC} ${PROJECT_SRC})
|
||||||
add_executable(${PROJECT_NAME} src/main.cpp)
|
add_executable(${PROJECT_NAME} src/main.cpp)
|
||||||
add_executable(anm2ed-cli src/cli.cpp)
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||||
@@ -149,8 +148,6 @@ set_target_properties(
|
|||||||
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/bin")
|
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
|
||||||
set_target_properties(anm2ed-cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
anm2ed_app
|
anm2ed_app
|
||||||
PUBLIC include
|
PUBLIC include
|
||||||
@@ -240,7 +237,6 @@ endif()
|
|||||||
target_link_libraries(anm2ed_app PUBLIC anm2ed_core ${OPENGL_LIB} SDL3-static SDL3_mixer::SDL3_mixer lunasvg
|
target_link_libraries(anm2ed_app PUBLIC anm2ed_core ${OPENGL_LIB} SDL3-static SDL3_mixer::SDL3_mixer lunasvg
|
||||||
${PLATFORM_LIBS})
|
${PLATFORM_LIBS})
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE anm2ed_app ${SDL_MAIN_TARGET})
|
target_link_libraries(${PROJECT_NAME} PRIVATE anm2ed_app ${SDL_MAIN_TARGET})
|
||||||
target_link_libraries(anm2ed-cli PRIVATE anm2ed_app)
|
|
||||||
|
|
||||||
option(ANM2ED_TESTS "Build the anm2ed test suite" ON)
|
option(ANM2ED_TESTS "Build the anm2ed test suite" ON)
|
||||||
if(ANM2ED_TESTS)
|
if(ANM2ED_TESTS)
|
||||||
@@ -260,7 +256,7 @@ if(ANM2ED_TESTS)
|
|||||||
target_compile_definitions(anm2ed_render_tests PRIVATE ANM2ED_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests"
|
target_compile_definitions(anm2ed_render_tests PRIVATE ANM2ED_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests"
|
||||||
ANM2ED_RENDER_DIR="${CMAKE_BINARY_DIR}/renders")
|
ANM2ED_RENDER_DIR="${CMAKE_BINARY_DIR}/renders")
|
||||||
add_test(NAME anm2ed_render_tests COMMAND anm2ed_render_tests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
add_test(NAME anm2ed_render_tests COMMAND anm2ed_render_tests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||||
add_test(NAME anm2ed_cli_info COMMAND anm2ed-cli info ${CMAKE_CURRENT_SOURCE_DIR}/tests/render/spin.anm2)
|
add_test(NAME anm2ed_cli_info COMMAND ${PROJECT_NAME} info ${CMAKE_CURRENT_SOURCE_DIR}/tests/render/spin.anm2)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
||||||
|
|||||||
@@ -57,10 +57,10 @@ ctest --test-dir build
|
|||||||
Render tests draw with OpenGL (skipped without a display) and leave their images in `build/renders`.
|
Render tests draw with OpenGL (skipped without a display) and leave their images in `build/renders`.
|
||||||
|
|
||||||
## Command Line
|
## Command Line
|
||||||
`anm2ed-cli` looks at a file without the editor, drawing with the editor's renderer:
|
`anm2ed <command>` looks at a file without opening the editor, drawing with the editor's renderer:
|
||||||
```sh
|
```sh
|
||||||
anm2ed-cli info file.anm2 # animations, items, spritesheets, Isaac issues
|
anm2ed info file.anm2 # animations, items, spritesheets, Isaac issues
|
||||||
anm2ed-cli frame file.anm2 --out frame.png --time 4 # one frame
|
anm2ed frame file.anm2 --out frame.png --time 4 # one frame
|
||||||
anm2ed-cli render file.anm2 --out sheet.png --scale 3 # every frame in a grid (--type pngs|gif|webm|mp4|ogv)
|
anm2ed render file.anm2 --out sheet.png --scale 3 # every frame in a grid (--type pngs|gif|webm|mp4|ogv)
|
||||||
```
|
```
|
||||||
Common options: `--animation NAME|INDEX`, `--scale`, `--fps`, `--start`/`--end`, `--background RRGGBB`. Run it without arguments for the full list.
|
Common options: `--animation NAME|INDEX`, `--scale`, `--fps`, `--start`/`--end`, `--background RRGGBB`. `anm2ed render` alone lists them all.
|
||||||
+16
-12
@@ -1,6 +1,6 @@
|
|||||||
// anm2ed-cli: look at .anm2 files without the editor - a text summary, or animations drawn (with the editor's own
|
#include "cli.hpp"
|
||||||
// OpenGL renderer, in a hidden window) to a PNG frame, a contact sheet, a PNG sequence, a GIF or a video.
|
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <format>
|
#include <format>
|
||||||
@@ -17,12 +17,11 @@
|
|||||||
#include "render.hpp"
|
#include "render.hpp"
|
||||||
#include "working_directory.hpp"
|
#include "working_directory.hpp"
|
||||||
|
|
||||||
using namespace anm2ed;
|
|
||||||
using namespace anm2ed::util;
|
using namespace anm2ed::util;
|
||||||
|
|
||||||
namespace anm2ed::cli
|
namespace anm2ed::cli
|
||||||
{
|
{
|
||||||
constexpr const char* USAGE = R"(usage: anm2ed-cli <command> <file.anm2> [options]
|
constexpr const char* USAGE = R"(usage: anm2ed <command> <file.anm2> [options]
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
info animations, items, spritesheets and Isaac compatibility, as text
|
info animations, items, spritesheets and Isaac compatibility, as text
|
||||||
@@ -75,7 +74,7 @@ options:
|
|||||||
return arguments.command == "render" && arguments.get("type").value_or("") == "pngs";
|
return arguments.command == "render" && arguments.get("type").value_or("") == "pngs";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Arguments> arguments_get(int argc, char** argv)
|
std::optional<Arguments> arguments_get(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3) return {};
|
if (argc < 3) return {};
|
||||||
Arguments arguments{.command = argv[1], .file = path::from_utf8(argv[2])};
|
Arguments arguments{.command = argv[1], .file = path::from_utf8(argv[2])};
|
||||||
@@ -267,18 +266,23 @@ options:
|
|||||||
std::println("");
|
std::println("");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr std::string_view COMMANDS[] = {"info", "frame", "render"};
|
||||||
|
|
||||||
|
bool is_cli(int argc, const char** argv)
|
||||||
|
{
|
||||||
|
return argc >= 2 && std::ranges::contains(COMMANDS, std::string_view(argv[1])) && !path::is_exist(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int run(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
auto arguments = cli::arguments_get(argc, argv);
|
auto arguments = arguments_get(argc, argv);
|
||||||
if (!arguments)
|
if (!arguments)
|
||||||
{
|
{
|
||||||
std::print(stderr, "{}", cli::USAGE);
|
std::print(stderr, "{}", USAGE);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if (arguments->command == "info") return cli::info_print(*arguments);
|
if (arguments->command == "info") return info_print(*arguments);
|
||||||
if (arguments->command == "frame" || arguments->command == "render") return cli::draw_run(*arguments);
|
return draw_run(*arguments);
|
||||||
std::print(stderr, "{}", cli::USAGE);
|
}
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// The command-line mode: "anm2ed <info|frame|render> <file.anm2> [options]" looks at a file without the editor, as
|
||||||
|
// text or drawn (by the editor's OpenGL renderer, in a hidden window) to a PNG frame, a contact sheet, PNGs, a GIF or
|
||||||
|
// a video.
|
||||||
|
namespace anm2ed::cli
|
||||||
|
{
|
||||||
|
bool is_cli(int, const char**);
|
||||||
|
int run(int, const char**);
|
||||||
|
}
|
||||||
+17
-2
@@ -1,3 +1,4 @@
|
|||||||
|
#include "cli.hpp"
|
||||||
#include "loader.hpp"
|
#include "loader.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "sdl.hpp"
|
#include "sdl.hpp"
|
||||||
@@ -6,11 +7,11 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
#include <shellapi.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellapi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -63,8 +64,22 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
int application_run(int argc, const char** argv)
|
int application_run(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
|
if (cli::is_cli(argc, argv))
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// A GUI-subsystem build has no console of its own; print to the one it was started from.
|
||||||
|
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||||
|
{
|
||||||
|
freopen("CONOUT$", "w", stdout);
|
||||||
|
freopen("CONOUT$", "w", stderr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return cli::run(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
logger.session_open(util::sdl::preferences_directory_get());
|
logger.session_open(util::sdl::preferences_directory_get());
|
||||||
return log_exceptions([&]()
|
return log_exceptions(
|
||||||
|
[&]()
|
||||||
{
|
{
|
||||||
Loader loader(argc, argv);
|
Loader loader(argc, argv);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user