diff --git a/container/plugins/root/example/example.cc b/container/plugins/root/example/example.cc index ad6f32b..17b776e 100644 --- a/container/plugins/root/example/example.cc +++ b/container/plugins/root/example/example.cc @@ -57,7 +57,7 @@ class example_cc final example_cc& operator=(example_cc&&) = default; public: - //! \brief Example auto-loader + //! \brief Example plugin's auto-loader //! \param arg String to pass to auto-loader (use-case is plugin-implementation defined) static void load(const std::string& arg = {}) { @@ -85,7 +85,7 @@ class example_cc final common::line(arg); } - //! \brief Example auto-unloader + //! \brief Example plugin's auto-unloader //! \param arg String to pass to auto-unloader (use-case is plugin-implementation defined) static void unload(const std::string& arg = {}) { diff --git a/container/plugins/root/example/internal/example.cc b/container/plugins/root/example/internal/example.cc index e810166..c20f0c8 100644 --- a/container/plugins/root/example/internal/example.cc +++ b/container/plugins/root/example/internal/example.cc @@ -1,6 +1,6 @@ // docker-finance | modern accounting for the power-user // -// Copyright (C) 2024-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +// Copyright (C) 2024-2026 Aaron Fiore (Founder, Evergreen Crypto LLC) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -26,12 +26,14 @@ namespace dfi::plugin::example { -std::string Example::make_cmd(const std::string& base, const std::string& arg) +std::string MyExamples::make_cmd( + const std::string& base, + const std::string& arg) { return std::string{base + arg}; } -void Example::exec_cmd(const std::string& cmd) +void MyExamples::exec_cmd(const std::string& cmd) { namespace common = ::dfi::common; @@ -42,16 +44,16 @@ void Example::exec_cmd(const std::string& cmd) + common::get_env("global_child_profile") + " "}; common::throw_ex_if( - common::exec("bash -i -c '" + Example::make_cmd(base, cmd) + "'"), + common::exec("bash -i -c '" + MyExamples::make_cmd(base, cmd) + "'"), "command failed"); } -void Example::print_env(const std::string& env) +void MyExamples::print_env(const std::string& env) { std::cout << env << "=" << ::dfi::common::get_env(env) << "\n"; }; -void Example::example1() +void MyExamples::example1() { using g_Random = dfi::crypto::cryptopp::Random; using g_Hash = dfi::crypto::libsodium::Hash; @@ -64,21 +66,21 @@ void Example::example1() } } -void Example::example2() +void MyExamples::example2() { // Container environment std::cout << "\nShell environment (container)\n-----------------------------\n"; - Example::print_env("DOCKER_FINANCE_CLIENT_FLOW"); - Example::print_env("DOCKER_FINANCE_CONTAINER_CMD"); - Example::print_env("DOCKER_FINANCE_CONTAINER_CONF"); - Example::print_env("DOCKER_FINANCE_CONTAINER_EDITOR"); - Example::print_env("DOCKER_FINANCE_CONTAINER_FLOW"); - Example::print_env("DOCKER_FINANCE_CONTAINER_PLUGINS"); - Example::print_env("DOCKER_FINANCE_CONTAINER_REPO"); - Example::print_env("DOCKER_FINANCE_CONTAINER_SHARED"); - Example::print_env("DOCKER_FINANCE_DEBUG"); - Example::print_env("DOCKER_FINANCE_VERSION"); + MyExamples::print_env("DOCKER_FINANCE_CLIENT_FLOW"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_CMD"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_CONF"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_EDITOR"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_FLOW"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_PLUGINS"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_REPO"); + MyExamples::print_env("DOCKER_FINANCE_CONTAINER_SHARED"); + MyExamples::print_env("DOCKER_FINANCE_DEBUG"); + MyExamples::print_env("DOCKER_FINANCE_VERSION"); std::cout << "\nSame as previous but executing commands in " "shell\n------------------------------------------------\n"; @@ -86,35 +88,35 @@ void Example::example2() // Caller environment std::cout << "\nShell environment (caller)\n--------------------------\n"; - Example::print_env("global_arg_delim_1"); - Example::print_env("global_arg_delim_2"); - Example::print_env("global_arg_delim_3"); - Example::print_env("global_arg_subcommand"); - Example::print_env("global_basename"); - Example::print_env("global_child_profile"); - Example::print_env("global_child_profile_flow"); - Example::print_env("global_child_profile_journal"); - Example::print_env("global_conf_fetch"); - Example::print_env("global_conf_hledger"); - Example::print_env("global_conf_meta"); - Example::print_env("global_conf_subscript"); + MyExamples::print_env("global_arg_delim_1"); + MyExamples::print_env("global_arg_delim_2"); + MyExamples::print_env("global_arg_delim_3"); + MyExamples::print_env("global_arg_subcommand"); + MyExamples::print_env("global_basename"); + MyExamples::print_env("global_child_profile"); + MyExamples::print_env("global_child_profile_flow"); + MyExamples::print_env("global_child_profile_journal"); + MyExamples::print_env("global_conf_fetch"); + MyExamples::print_env("global_conf_hledger"); + MyExamples::print_env("global_conf_meta"); + MyExamples::print_env("global_conf_subscript"); // TODO(unassigned): read array from shell? ROOT impl simply calls stdlib getenv() - // Example::print_env("global_hledger_cmd"); - Example::print_env("global_parent_profile"); - Example::print_env("global_usage"); + // MyExamples::print_env("global_hledger_cmd"); + MyExamples::print_env("global_parent_profile"); + MyExamples::print_env("global_usage"); } -void Example::example3() +void MyExamples::example3() { std::cout << "\nImporting journals...\n"; - Example::exec_cmd("import 1>/dev/null"); + MyExamples::exec_cmd("import 1>/dev/null"); std::cout << "\nShowing BTC balance...\n"; - Example::exec_cmd("hledger bal assets liabilities cur:BTC"); + MyExamples::exec_cmd("hledger bal assets liabilities cur:BTC"); std::cout << "\nGenerating income tax snippet...\n"; const std::string delim{::dfi::common::get_env("global_arg_delim_2")}; - Example::exec_cmd( + MyExamples::exec_cmd( "taxes all" + delim + "account tag" + delim + "income write" + delim + "off | tail -n3"); } diff --git a/container/plugins/root/example/internal/example.hh b/container/plugins/root/example/internal/example.hh index d93e8d7..94e649c 100644 --- a/container/plugins/root/example/internal/example.hh +++ b/container/plugins/root/example/internal/example.hh @@ -1,6 +1,6 @@ // docker-finance | modern accounting for the power-user // -// Copyright (C) 2024-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +// Copyright (C) 2024-2026 Aaron Fiore (Founder, Evergreen Crypto LLC) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ namespace dfi::plugin::example //! //! \ingroup cpp_plugin_impl //! \since docker-finance 1.1.0 -class Example +class MyExamples { public: //! \brief Example plugin function 1 diff --git a/container/src/finance/lib/internal/lib_root.bash b/container/src/finance/lib/internal/lib_root.bash index 88bcdc2..366380c 100644 --- a/container/src/finance/lib/internal/lib_root.bash +++ b/container/src/finance/lib/internal/lib_root.bash @@ -2,7 +2,7 @@ # docker-finance | modern accounting for the power-user # -# Copyright (C) 2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +# Copyright (C) 2025-2026 Aaron Fiore (Founder, Evergreen Crypto LLC) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -97,19 +97,19 @@ function lib_root::__parse_root() ... Interpreting: 'int i{123}; i' (int) 123 - root [3] dfi::plugin::example::Example e; // Plugin's Example class is now available to use - root [4] e.example2() + root [3] dfi::plugin::example::MyExamples my; // Plugin's MyExamples class is now available to use + root [4] my.example2() ... root [5] g_plugin_example_cc.unload() // Plugin is a global instance based on Pluggable entrypoint name Interpreting: 'dfi::plugin::example::example_cc::unload(\"std::cout << --i << std::endl;\")' Interpreting: 'std::cout << --i << std::endl;' 122 ... - root [6] e.example2() // Since plugin has been unloaded, this is expected to not compile + root [6] my.example2() // Since plugin has been unloaded, this is expected to not compile input_line_27:2:3: error: use of undeclared identifier 'e' - (e.example2()) + (my.example2()) ^ - Error in : Error evaluating expression (e.example2()) + Error in : Error evaluating expression (my.example2()) Execution of your code was aborted. root [7] .quit $ diff --git a/container/src/root/test/unit/utility.hh b/container/src/root/test/unit/utility.hh index 0981cea..e74db59 100644 --- a/container/src/root/test/unit/utility.hh +++ b/container/src/root/test/unit/utility.hh @@ -933,7 +933,7 @@ struct PluginCommands : public ::testing::Test, const std::string kValidFile{"repo/example/example.cc"}; const std::string kInvalidFile{"repo/should-not/exist.cc"}; - const std::string kValidArg{"dfi::plugin::example::Example e;"}; + const std::string kValidArg{"dfi::plugin::example::MyExamples my;"}; //! \note File is processed but plugin-implementation argument will intentionally throw const std::string kInvalidArg{ @@ -957,16 +957,16 @@ TEST_F(PluginCommands, LoadUnloadSingleSimpleNoArg) TEST_F(PluginCommands, LoadUnloadSingleSimpleWithArg) { - ASSERT_NO_THROW(plugin::load(kValidFile, kValidArg + " e.example1();")); + ASSERT_NO_THROW(plugin::load(kValidFile, kValidArg + " my.example1();")); ASSERT_NO_THROW(plugin::unload(kValidFile)); ASSERT_THROW( plugin::load(kValidFile, kInvalidArg), common::type::InvalidArgument); ASSERT_NO_THROW(common::line(kValidArg)); // File is still loaded - ASSERT_NO_THROW(plugin::unload(kValidFile, kValidArg + " e.example1();")); + ASSERT_NO_THROW(plugin::unload(kValidFile, kValidArg + " my.example1();")); ASSERT_THROW( - common::line(kValidArg + " e.example1();"), common::type::RuntimeError); + common::line(kValidArg + " my.example1();"), common::type::RuntimeError); } TEST_F(PluginCommands, LoadUnloadSinglePluggable) @@ -975,13 +975,14 @@ TEST_F(PluginCommands, LoadUnloadSinglePluggable) plugin::load( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " e.example1();", kValidArg + " /* unload code */"})); + kValidArg + " my.example1();", + kValidArg + " /* unload code */"})); ASSERT_NO_THROW( plugin::unload( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " /* load code */", kValidArg + " e.example2();"})); + kValidArg + " /* load code */", kValidArg + " my.example2();"})); ASSERT_THROW( plugin::load( @@ -995,12 +996,12 @@ TEST_F(PluginCommands, LoadUnloadSinglePluggable) plugin::unload( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " /* load code */", kValidArg + " e.example2();"})); + kValidArg + " /* load code */", kValidArg + " my.example2();"})); ASSERT_THROW( - common::line(kValidArg + " e.example1();"), common::type::RuntimeError); + common::line(kValidArg + " my.example1();"), common::type::RuntimeError); ASSERT_THROW( - common::line(kValidArg + " e.example2();"), common::type::RuntimeError); + common::line(kValidArg + " my.example2();"), common::type::RuntimeError); } // TODO(afiore): multiple load @@ -1026,7 +1027,7 @@ TEST_F(PluginCommands, ReloadSingleSimpleNoArg) TEST_F(PluginCommands, ReloadSingleSimpleWithArg) { - ASSERT_NO_THROW(plugin::load(kValidFile, kValidArg + " e.example1();")); + ASSERT_NO_THROW(plugin::load(kValidFile, kValidArg + " my.example1();")); ASSERT_NO_THROW( plugin::reload( @@ -1048,9 +1049,9 @@ TEST_F(PluginCommands, ReloadSingleSimpleWithArg) kValidFile, {kValidArg + " /* load code */", kValidArg + " /* unload code */"})); - ASSERT_NO_THROW(plugin::unload(kValidFile, kValidArg + " e.example1();")); + ASSERT_NO_THROW(plugin::unload(kValidFile, kValidArg + " my.example1();")); ASSERT_THROW( - common::line(kValidArg + " e.example1();"), common::type::RuntimeError); + common::line(kValidArg + " my.example1();"), common::type::RuntimeError); } TEST_F(PluginCommands, ReloadSinglePluggable) @@ -1059,13 +1060,14 @@ TEST_F(PluginCommands, ReloadSinglePluggable) plugin::load( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " e.example1();", kValidArg + " /* unload code */"})); + kValidArg + " my.example1();", + kValidArg + " /* unload code */"})); ASSERT_NO_THROW( plugin::reload( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " e.example1();", kValidArg + " e.example2();"})); + kValidArg + " my.example1();", kValidArg + " my.example2();"})); ASSERT_THROW( plugin::load( @@ -1079,7 +1081,7 @@ TEST_F(PluginCommands, ReloadSinglePluggable) plugin::reload( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " e.example1();", kValidArg + " e.example2();"})); + kValidArg + " my.example1();", kValidArg + " my.example2();"})); ASSERT_NO_THROW(common::line(kValidArg)); @@ -1087,15 +1089,15 @@ TEST_F(PluginCommands, ReloadSinglePluggable) plugin::unload( plugin::common::PluginPath{kValidFile}, plugin::common::PluginArgs{ - kValidArg + " /* load code */", kValidArg + " e.example3();"})); + kValidArg + " /* load code */", kValidArg + " my.example3();"})); ASSERT_THROW(common::line(kValidArg), common::type::RuntimeError); ASSERT_THROW( - common::line(kValidArg + " e.example1();"), common::type::RuntimeError); + common::line(kValidArg + " my.example1();"), common::type::RuntimeError); ASSERT_THROW( - common::line(kValidArg + " e.example2();"), common::type::RuntimeError); + common::line(kValidArg + " my.example2();"), common::type::RuntimeError); ASSERT_THROW( - common::line(kValidArg + " e.example3();"), common::type::RuntimeError); + common::line(kValidArg + " my.example3();"), common::type::RuntimeError); } TEST_F(PluginCommands, LoaderNPI) @@ -1107,7 +1109,7 @@ TEST_F(PluginCommands, LoaderNPI) ::dfi::common::type::Pluggable type{ t_path{kValidFile}, t_space{"example" /* inner */, "example_cc" /* class */}, - t_args{kValidArg + " e.example1();", kValidArg + " e.example2();"}}; + t_args{kValidArg + " my.example1();", kValidArg + " my.example2();"}}; plugin::common::Plugin plugin{type}; ASSERT_NO_THROW(plugin.load().reload().unload());