Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
cli.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <functional>
5#include <optional>
6#include <string>
7#include <vector>
8
14struct CliOptions {
15 enum class Mode {
16 Help,
17 ListCpp,
19 Cpp,
20 Json
21 };
22
24 std::string target;
25 bool plot = true;
26 bool verbose = false;
28 std::vector<std::filesystem::path> jsonPathOverrides;
30 std::vector<std::filesystem::path> extraSearchPaths;
32 std::vector<std::filesystem::path> searchPaths;
33};
34
35using ExampleFn = std::function<void(bool plotting_enabled)>;
36
38void initCliPaths(const char* argv0);
39
41std::optional<std::filesystem::path> harmonyRepoRoot();
42
44CliOptions parseCli(int argc, char* argv[]);
45
47void printCliHelp();
48
50void listCppExamples();
51
53std::vector<std::string> cppExampleNames();
54
56void listJsonFiles(const std::vector<std::filesystem::path>& searchPaths);
57
59std::vector<std::filesystem::path> discoverJsonFiles(
60 const std::vector<std::filesystem::path>& searchPaths);
61
63bool validateJsonFile(const std::filesystem::path& jsonPath, std::string& errorOut);
64
66int runCppExample(const std::string& name, bool plot, bool verbose);
67
73 const std::filesystem::path& jsonPath,
74 bool verbose,
75 bool plot = true,
76 bool waitForPlotClose = true);
77
79std::vector<std::filesystem::path> builtinJsonSearchPaths();
80
82std::vector<std::filesystem::path> jsonSearchPathsFromEnvironment();
83
85std::vector<std::filesystem::path> defaultJsonSearchPaths();
86
92std::vector<std::filesystem::path> buildJsonSearchPaths(
93 const std::vector<std::filesystem::path>& jsonPathOverrides,
94 const std::vector<std::filesystem::path>& extraSearchPaths);
95
97std::filesystem::path resolveJsonPath(
98 const std::string& input,
99 const std::vector<std::filesystem::path>& searchPaths);
100
103 const std::string& input,
104 const std::vector<std::filesystem::path>& searchPaths);
std::vector< std::filesystem::path > buildJsonSearchPaths(const std::vector< std::filesystem::path > &jsonPathOverrides, const std::vector< std::filesystem::path > &extraSearchPaths)
Build the effective JSON search path list for one invocation.
Definition cli.cpp:209
std::function< void(bool plotting_enabled)> ExampleFn
Definition cli.h:35
std::vector< std::filesystem::path > defaultJsonSearchPaths()
Default paths: HARMONY_JSON_PATH if set, otherwise builtinJsonSearchPaths.
Definition cli.cpp:200
void listJsonFiles(const std::vector< std::filesystem::path > &searchPaths)
List JSON files found under configured search paths.
Definition cli.cpp:407
std::optional< std::filesystem::path > harmonyRepoRoot()
Detected Harmony repository root, if any.
Definition cli.cpp:103
int runJsonSimulation(const std::filesystem::path &jsonPath, bool verbose, bool plot=true, bool waitForPlotClose=true)
Run a JSON simulation file.
Definition cli.cpp:537
CliOptions parseCli(int argc, char *argv[])
Parse argc/argv into CliOptions.
Definition cli.cpp:237
std::filesystem::path resolveJsonPath(const std::string &input, const std::vector< std::filesystem::path > &searchPaths)
Resolve a JSON path (absolute, relative, or filename in search paths).
Definition cli.cpp:444
void listCppExamples()
List registered C++ examples.
Definition cli.cpp:328
int runCppExample(const std::string &name, bool plot, bool verbose)
Run a named C++ example.
Definition cli.cpp:512
bool validateJsonFile(const std::filesystem::path &jsonPath, std::string &errorOut)
Parse and schema-validate a JSON simulation file.
Definition cli.cpp:373
void printCliHelp()
Print usage text to stdout.
Definition cli.cpp:298
void initCliPaths(const char *argv0)
Resolve executable location for repo-root detection (call once from main).
Definition cli.cpp:90
std::vector< std::filesystem::path > jsonSearchPathsFromEnvironment()
Paths from HARMONY_JSON_PATH, or empty if the variable is unset.
Definition cli.cpp:189
std::vector< std::filesystem::path > discoverJsonFiles(const std::vector< std::filesystem::path > &searchPaths)
Discover .json files under searchPaths (sorted, unique).
Definition cli.cpp:350
std::vector< std::filesystem::path > builtinJsonSearchPaths()
Built-in JSON search directories (used when env/CLI overrides are unset).
Definition cli.cpp:178
std::vector< std::string > cppExampleNames()
Registered C++ example names (sorted).
Definition cli.cpp:337
void printJsonNotFoundHelp(const std::string &input, const std::vector< std::filesystem::path > &searchPaths)
Print why a JSON file was not found (search paths, repo root, env).
Definition cli.cpp:478
Definition cli.h:14
std::vector< std::filesystem::path > jsonPathOverrides
From --json-path (replaces defaults when non-empty).
Definition cli.h:28
std::vector< std::filesystem::path > searchPaths
Effective search list built in parseCli.
Definition cli.h:32
bool verbose
Definition cli.h:26
Mode
Definition cli.h:15
bool plot
Definition cli.h:25
Mode mode
Definition cli.h:23
std::vector< std::filesystem::path > extraSearchPaths
From --search-path (appended after defaults).
Definition cli.h:30
std::string target
Definition cli.h:24