55 */
66#include " CommandGenerator.hpp"
77#include " ../arguments/ArgumentManager.hpp"
8+ #include " ../arguments/Constants.hpp"
89#include " Constants.hpp"
910#include < filesystem>
1011#include < iomanip>
1112#include < libintl.h>
1213#include < sstream>
1314
1415#define _ (string ) gettext(string)
16+
1517namespace fs = std::filesystem;
1618
1719namespace CommandGenerator {
1820
1921std::string GenerateCommand (CommandFormat format)
2022{
23+ using namespace DynaRange ::Arguments::Constants;
2124 std::stringstream command_ss;
2225 command_ss << DynaRange::Utils::Constants::CLI_EXECUTABLE_NAME;
2326 auto & mgr = ArgumentManager::Instance ();
@@ -28,104 +31,103 @@ std::string GenerateCommand(CommandFormat format)
2831 command_ss << " --" << name;
2932 return ;
3033 }
31- // Map long names to short names for the short command format
34+
3235 static const std::map<std::string, std::string> short_map
33- = { { " black-level " , " -B" }, { " black-file " , " -b" }, { " saturation-level " , " -S" }, { " saturation-file " , " -s" }, { " input-files " , " -i" }, { " patch-ratio " , " -r" },
34- { " snrthreshold-db " , " -d" }, { " drnormalization-mpx " , " -m" }, { " poly-fit " , " -f" }, { " output-file " , " -o" }, { " plot-format " , " -p" }, { " plot-params " , " -P" },
35- { " print-patches " , " -g" }, { " raw-channel " , " -w" }, { " chart " , " -c" }, { " chart-colour " , " -C" }, { " chart-coords " , " -x" }, { " chart-patches " , " -M" } };
36+ = { { BlackLevel , " -B" }, { BlackFile , " -b" }, { SaturationLevel , " -S" }, { SaturationFile , " -s" }, { InputFiles , " -i" }, { PatchRatio , " -r" },
37+ { SnrThresholdDb , " -d" }, { DrNormalizationMpx , " -m" }, { PolyFit , " -f" }, { OutputFile , " -o" }, { PlotFormat , " -p" }, { PlotParams , " -P" },
38+ { PrintPatches , " -g" }, { RawChannels , " -w" }, { Chart , " -c" }, { ChartColour , " -C" }, { ChartCoords , " -x" }, { ChartPatches , " -M" } };
3639 auto it = short_map.find (name);
3740 if (it != short_map.end ()) {
3841 command_ss << it->second ;
3942 } else {
40- command_ss << " --" << name; // Fallback for args without a short version
43+ command_ss << " --" << name;
4144 }
4245 };
4346
44- std::string black_file = mgr.Get <std::string>(" black-file " );
47+ std::string black_file = mgr.Get <std::string>(BlackFile );
4548 if (!black_file.empty ()) {
46- add_arg (" black-file " );
49+ add_arg (BlackFile );
4750 if (format == CommandFormat::GuiPreview || format == CommandFormat::Full) {
4851 command_ss << " \" " << black_file << " \" " ;
4952 } else {
5053 command_ss << " \" " << fs::path (black_file).filename ().string () << " \" " ;
5154 }
5255 } else {
53- add_arg (" black-level " );
54- command_ss << " " << std::fixed << std::setprecision (2 ) << mgr.Get <double >(" black-level " );
56+ add_arg (BlackLevel );
57+ command_ss << " " << std::fixed << std::setprecision (2 ) << mgr.Get <double >(BlackLevel );
5558 }
5659
57- std::string sat_file = mgr.Get <std::string>(" saturation-file " );
60+ std::string sat_file = mgr.Get <std::string>(SaturationFile );
5861 if (!sat_file.empty ()) {
59- add_arg (" saturation-file " );
62+ add_arg (SaturationFile );
6063 if (format == CommandFormat::GuiPreview || format == CommandFormat::Full) {
6164 command_ss << " \" " << sat_file << " \" " ;
6265 } else {
6366 command_ss << " \" " << fs::path (sat_file).filename ().string () << " \" " ;
6467 }
6568 } else {
66- add_arg (" saturation-level " );
67- command_ss << " " << std::fixed << std::setprecision (2 ) << mgr.Get <double >(" saturation-level " );
69+ add_arg (SaturationLevel );
70+ command_ss << " " << std::fixed << std::setprecision (2 ) << mgr.Get <double >(SaturationLevel );
6871 }
6972
7073 if (format == CommandFormat::Full) {
71- add_arg (" output-file " );
72- command_ss << " \" " << mgr.Get <std::string>(" output-file " ) << " \" " ;
74+ add_arg (OutputFile );
75+ command_ss << " \" " << mgr.Get <std::string>(OutputFile ) << " \" " ;
7376 }
7477
75- if (!mgr.Get <bool >(" snr-threshold-is-default " )) {
76- add_arg (" snrthreshold-db " );
77- const auto & thresholds = mgr.Get <std::vector<double >>(" snrthreshold-db " );
78+ if (!mgr.Get <bool >(SnrThresholdIsDefault )) {
79+ add_arg (SnrThresholdDb );
80+ const auto & thresholds = mgr.Get <std::vector<double >>(SnrThresholdDb );
7881 for (const auto & threshold : thresholds) {
7982 command_ss << " " << threshold;
8083 }
8184 }
8285
83- add_arg (" drnormalization-mpx " );
84- command_ss << " " << mgr.Get <double >(" drnormalization-mpx " );
85- add_arg (" poly-fit " );
86- command_ss << " " << mgr.Get <int >(" poly-fit " );
87- add_arg (" patch-ratio " );
88- command_ss << " " << mgr.Get <double >(" patch-ratio " );
86+ add_arg (DrNormalizationMpx );
87+ command_ss << " " << mgr.Get <double >(DrNormalizationMpx );
88+ add_arg (PolyFit );
89+ command_ss << " " << mgr.Get <int >(PolyFit );
90+ add_arg (PatchRatio );
91+ command_ss << " " << mgr.Get <double >(PatchRatio );
8992
90- if (mgr.Get <bool >(" generate-plot " )) {
91- add_arg (" plot-format " );
92- command_ss << " " << mgr.Get <std::string>(" plot-format " );
93+ if (mgr.Get <bool >(GeneratePlot )) {
94+ add_arg (PlotFormat );
95+ command_ss << " " << mgr.Get <std::string>(PlotFormat );
9396
94- add_arg (" plot-params " );
95- const auto & plot_params = mgr.Get <std::vector<int >>(" plot-params " );
97+ add_arg (PlotParams );
98+ const auto & plot_params = mgr.Get <std::vector<int >>(PlotParams );
9699 for (const auto & val : plot_params) {
97100 command_ss << " " << val;
98101 }
99102 }
100103
101- const auto & chart_coords = mgr.Get <std::vector<double >>(" chart-coords " );
104+ const auto & chart_coords = mgr.Get <std::vector<double >>(ChartCoords );
102105 if (!chart_coords.empty ()) {
103- add_arg (" chart-coords " );
106+ add_arg (ChartCoords );
104107 for (const auto & coord : chart_coords)
105108 command_ss << " " << coord;
106109 }
107110
108- const auto & chart_patches = mgr.Get <std::vector<int >>(" chart-patches " );
111+ const auto & chart_patches = mgr.Get <std::vector<int >>(ChartPatches );
109112 if (!chart_patches.empty ()) {
110- add_arg (" chart-patches " );
113+ add_arg (ChartPatches );
111114 for (const auto & val : chart_patches)
112115 command_ss << " " << val;
113116 }
114117
115- // Add --raw-channel to the command string if it's not the default.
116- const auto & raw_channels_vec = mgr.Get <std::vector<int >>(" raw-channel" );
118+ const auto & raw_channels_vec = mgr.Get <std::vector<int >>(RawChannels);
117119 const std::vector<int > default_channels = { 0 , 0 , 0 , 0 , 1 };
118120 if (raw_channels_vec != default_channels) {
119- add_arg (" raw-channel " );
121+ add_arg (RawChannels );
120122 for (const auto & val : raw_channels_vec) {
121123 command_ss << " " << val;
122124 }
123125 }
124126
125127 if (format == CommandFormat::Full || format == CommandFormat::GuiPreview) {
126- const auto & input_files = mgr.Get <std::vector<std::string>>(" input-files " );
128+ const auto & input_files = mgr.Get <std::vector<std::string>>(InputFiles );
127129 if (!input_files.empty ()) {
128- add_arg (" input-files " );
130+ add_arg (InputFiles );
129131 for (const auto & file : input_files) {
130132 command_ss << " \" " << file << " \" " ;
131133 }
0 commit comments