diff --git a/syncthing/CMakeLists.txt b/syncthing/CMakeLists.txt index 1fe35c0..2c448c9 100644 --- a/syncthing/CMakeLists.txt +++ b/syncthing/CMakeLists.txt @@ -123,7 +123,7 @@ file( "${SYNCTHING_PATH}/c-bindings/*.go" "${SYNCTHING_PATH}/c-bindings/*.h" "${SYNCTHING_PATH}/c-bindings/*.c" - "${SYNCTHING_PATH}/cmd/syncthing/cli/*.go" + "${SYNCTHING_PATH}/cmd/syncthing/*.go" "${SYNCTHING_PATH}/lib/*.go" "${SYNCTHING_PATH}/lib/*.h" "${SYNCTHING_PATH}/lib/*.c") @@ -187,19 +187,6 @@ add_custom_command( WORKING_DIRECTORY "${SYNCTHING_PATH}" COMMENT "Building Syncthing itself (as library)") -# add target to compile Syncthing as standalone executable (helpful for testing) -set(SYNCTHING_EXECUTABLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/syncthing") -add_custom_target( - syncthing_executable - COMMAND - "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" "AR=${CMAKE_C_COMPILER_AR}" "GOOS=${GO_TARGET_OS}" - "CGO_CFLAGS=${CGO_CFLAGS}" "CGO_CXXFLAGS=${CGO_CXXFLAGS}" "CGO_LDFLAGS=${CGO_LDFLAGS}" "GOARCH=${GO_TARGET_ARCH}" - "CGO_ENABLED=1" "GO111MODULE=on" "GOPATH=${GO_DEVELOPMENT_PATH}" "GOFLAGS=${GO_FLAGS}" "${GO_BIN}" build -v - -buildmode exe -o "${SYNCTHING_EXECUTABLE_PATH}" -ldflags "${GO_LINKER_FLAGS}" ./cmd/syncthing - DEPENDS ${SRC_FILES_SYNCTHING} - WORKING_DIRECTORY "${SYNCTHING_PATH}" - COMMENT "Building Syncthing itself (as executable, ${SYNCTHING_EXECUTABLE_PATH})") - # find c++utilities to use CMake modules and headers from it privately find_package(${PACKAGE_NAMESPACE_PREFIX}c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS}) diff --git a/syncthing/go/src/github.com/syncthing/syncthing b/syncthing/go/src/github.com/syncthing/syncthing index a2a6a3d..b3d2cc9 160000 --- a/syncthing/go/src/github.com/syncthing/syncthing +++ b/syncthing/go/src/github.com/syncthing/syncthing @@ -1 +1 @@ -Subproject commit a2a6a3d3f0fda2b665ca97168608e6d2a390cc20 +Subproject commit b3d2cc90542c2d6a617f41152d6897294df15577 diff --git a/syncthing/interface.cpp b/syncthing/interface.cpp index 4b179cd..36d5e19 100644 --- a/syncthing/interface.cpp +++ b/syncthing/interface.cpp @@ -213,15 +213,37 @@ string longSyncthingVersion() } /*! - * \brief Runs Syncthing's CLI with the specified \a args. + * \brief Sets the \a command and arguments to be run via ::libst_run_cli(). */ -long long runCli(const std::vector &args) +static void setArguments( + const char *command, std::vector::const_iterator argumentsBegin, std::vector::const_iterator argumentsEnd) { - ::libst_clear_cli_args(); - for (const auto *const arg : args) { - ::libst_append_cli_arg(gostr(arg)); + ::libst_clear_cli_args(gostr(command)); + for (; argumentsBegin != argumentsEnd; ++argumentsBegin) { + ::libst_append_cli_arg(gostr(*argumentsBegin)); } +} + +/*! + * \brief Runs Syncthing's top-level command "cli" with the specified \a arguments. + */ +long long runCli(const std::vector &arguments) +{ + setArguments("cli", arguments.cbegin(), arguments.cend()); return ::libst_run_cli(); } +/*! + * \brief Runs the Syncthing command using the specified \a arguments. + */ +long long runCommand(const std::vector &arguments) +{ + if (arguments.empty()) { + setArguments("--help", std::vector::const_iterator(), std::vector::const_iterator()); + } else { + setArguments(arguments.front(), ++arguments.begin(), arguments.end()); + } + return ::libst_run_main(); +} + } // namespace LibSyncthing diff --git a/syncthing/interface.h b/syncthing/interface.h index 080c30a..bdcec96 100644 --- a/syncthing/interface.h +++ b/syncthing/interface.h @@ -59,7 +59,8 @@ LIB_SYNCTHING_EXPORT std::int64_t stopSyncthing(); LIB_SYNCTHING_EXPORT std::string ownDeviceId(); LIB_SYNCTHING_EXPORT std::string syncthingVersion(); LIB_SYNCTHING_EXPORT std::string longSyncthingVersion(); -LIB_SYNCTHING_EXPORT long long runCli(const std::vector &args); +LIB_SYNCTHING_EXPORT long long runCli(const std::vector &arguments); +LIB_SYNCTHING_EXPORT long long runCommand(const std::vector &arguments); } // namespace LibSyncthing diff --git a/syncthing/tests/interfacetests.cpp b/syncthing/tests/interfacetests.cpp index cf2d8b0..8e701d8 100644 --- a/syncthing/tests/interfacetests.cpp +++ b/syncthing/tests/interfacetests.cpp @@ -31,7 +31,8 @@ class InterfaceTests : public TestFixture { CPPUNIT_TEST(testVersion); CPPUNIT_TEST(testRunWithoutConfig); CPPUNIT_TEST(testRunWithConfig); - CPPUNIT_TEST(testCli); + CPPUNIT_TEST(testRunCli); + CPPUNIT_TEST(testRunCommand); CPPUNIT_TEST_SUITE_END(); public: @@ -41,7 +42,8 @@ public: void testVersion(); void testRunWithoutConfig(); void testRunWithConfig(); - void testCli(); + void testRunCli(); + void testRunCommand(); void setUp() override; void tearDown() override; @@ -254,7 +256,15 @@ void InterfaceTests::testRunWithConfig() /*! * \brief Tests running Syncthing's CLI. */ -void InterfaceTests::testCli() +void InterfaceTests::testRunCli() { CPPUNIT_ASSERT_EQUAL_MESSAGE("run arbitrary CLI command", 0ll, runCli({ "config", "version", "--help" })); } + +/*! + * \brief Tests running Syncthing command. + */ +void InterfaceTests::testRunCommand() +{ + CPPUNIT_ASSERT_EQUAL_MESSAGE("run arbitrary CLI command", 0ll, runCommand({ "--help" })); +} diff --git a/tray/application/main.cpp b/tray/application/main.cpp index bcdf9f8..f3448c4 100644 --- a/tray/application/main.cpp +++ b/tray/application/main.cpp @@ -181,16 +181,21 @@ static int runApplication(int argc, const char *const *argv) widgetsGuiArg.addSubArguments({ &windowedArg, &showWebUiArg, &triggerArg, &waitForTrayArg, &connectionArg, &configPathArg, &singleInstanceArg, &newInstanceArg, &replaceArg, &showWizardArg, &assumeFirstLaunchArg, &wipArg }); #ifdef SYNCTHINGTRAY_USE_LIBSYNCTHING - auto cliArg = OperationArgument("cli", 'c', "run Syncthing's CLI"); - auto cliHelp = ConfigValueArgument("help", 'h', "show help for Syncthing's CLI"); + auto cliArg = OperationArgument("cli", 'c', "runs Syncthing's CLI"); + auto cliHelp = ConfigValueArgument("help", 'h', "shows help for Syncthing's CLI"); cliArg.setRequiredValueCount(Argument::varValueCount); cliArg.setFlags(Argument::Flags::Greedy, true); cliArg.setSubArguments({ &cliHelp }); + auto syncthingArg = OperationArgument("syncthing", '\n', "runs Syncthing"); + auto syncthingHelp = ConfigValueArgument("help", 'h', "lists Syncthing's top-level commands"); + syncthingArg.setRequiredValueCount(Argument::varValueCount); + syncthingArg.setFlags(Argument::Flags::Greedy, true); + syncthingArg.setSubArguments({ &syncthingHelp }); #endif parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), #ifdef SYNCTHINGTRAY_USE_LIBSYNCTHING - &cliArg, + &cliArg, &syncthingArg, #endif &parser.noColorArg(), &parser.helpArg(), &quitArg }); @@ -201,6 +206,10 @@ static int runApplication(int argc, const char *const *argv) CMD_UTILS_START_CONSOLE; return static_cast(LibSyncthing::runCli(cliArg.values())); } + if (syncthingArg.isPresent()) { + CMD_UTILS_START_CONSOLE; + return static_cast(LibSyncthing::runCommand(syncthingArg.values())); + } #endif // quit already running application if quit is present