@@ -90,52 +90,72 @@ buildcc::env::LogLevel loglevel_{buildcc::env::LogLevel::Info};
90
90
fs::path project_root_dir_{" " };
91
91
fs::path project_build_dir_{" _internal" };
92
92
93
- // Internal
94
- // std::unique_ptr<CLI::App> app_;
95
- // CLI::App *toolchain_{nullptr};
96
- // CLI::App *target_{nullptr};
97
-
98
- struct ArgsInstance {
99
- CLI::App app_{" BuildCC Buildsystem" };
100
- CLI::App *toolchain_{nullptr };
101
- CLI::App *target_{nullptr };
102
- };
103
-
104
- std::unique_ptr<ArgsInstance> args_instance_;
105
-
106
93
} // namespace
107
94
108
95
namespace buildcc {
109
96
110
- void Args::Init () {
111
- if (!args_instance_) {
112
- args_instance_ = std::make_unique<ArgsInstance>();
113
- args_instance_->toolchain_ =
97
+ std::unique_ptr<Args::Internal> Args::internal_;
98
+
99
+ Args::Instance &Args::Init () {
100
+ if (!internal_) {
101
+ internal_ = std::make_unique<Internal>();
102
+ internal_->toolchain =
114
103
Ref ().add_subcommand (kToolchainSubcommand , kToolchainDesc );
115
- args_instance_->target_ =
116
- Ref ().add_subcommand (kTargetSubcommand , kTargetDesc );
104
+ internal_->target = Ref ().add_subcommand (kTargetSubcommand , kTargetDesc );
117
105
RootArgs ();
118
106
}
107
+ return internal_->instance ;
119
108
}
120
109
121
- void Args::Deinit () { args_instance_.reset (nullptr ); }
122
-
123
- CLI::App &Args::Ref () { return args_instance_->app_ ; }
124
- const CLI::App &Args::ConstRef () { return args_instance_->app_ ; }
110
+ void Args::Deinit () { internal_.reset (nullptr ); }
125
111
126
112
bool Args::Clean () { return clean_; }
127
113
env::LogLevel Args::GetLogLevel () { return loglevel_; }
128
114
129
115
const fs::path &Args::GetProjectRootDir () { return project_root_dir_; }
130
116
const fs::path &Args::GetProjectBuildDir () { return project_build_dir_; }
131
117
132
- void Args::AddToolchain (const std::string &name, const std::string &description,
133
- ArgToolchain &out, const ArgToolchain &initial) {
134
- CLI::App *toolchain_ = args_instance_->toolchain_ ;
135
- env::assert_fatal (toolchain_ != nullptr ,
118
+ // Private
119
+
120
+ void Args::RootArgs () {
121
+ auto &app = Ref ();
122
+ app.set_help_all_flag (kHelpAllParam , kHelpAllDesc );
123
+
124
+ app.set_config (kConfigParam , " " , kConfigDesc )->expected (kMinFiles , kMaxFiles );
125
+
126
+ // Root flags
127
+ auto *root_group = app.add_option_group (kRootGroup );
128
+
129
+ root_group->add_flag (kCleanParam , clean_, kCleanDesc );
130
+ root_group->add_option (kLoglevelParam , loglevel_, kLoglevelDesc )
131
+ ->transform (CLI::CheckedTransformer (kLogLevelMap , CLI::ignore_case));
132
+
133
+ // Dir flags
134
+ root_group->add_option (kRootDirParam , project_root_dir_, kRootDirDesc )
135
+ ->required ();
136
+ root_group->add_option (kBuildDirParam , project_build_dir_, kBuildDirDesc )
137
+ ->required ();
138
+ }
139
+
140
+ CLI::App &Args::Ref () { return internal_->app ; }
141
+
142
+ // Args::Instance
143
+
144
+ /* *
145
+ * @brief Add toolchain with a unique name and description
146
+ *
147
+ * @param out Receive the toolchain information through the CLI
148
+ * @param initial Set the default toolchain information as a fallback
149
+ */
150
+ Args::Instance &Args::Instance::AddToolchain (const std::string &name,
151
+ const std::string &description,
152
+ ArgToolchain &out,
153
+ const ArgToolchain &initial) {
154
+ CLI::App *toolchain = internal_->toolchain ;
155
+ env::assert_fatal (toolchain != nullptr ,
136
156
" Initialize Args using the Args::Init API" );
137
157
CLI::App *t_user =
138
- toolchain_ ->add_subcommand (name, description)->group (kToolchainGroup );
158
+ toolchain ->add_subcommand (name, description)->group (kToolchainGroup );
139
159
t_user->add_flag (kToolchainBuildParam , out.state .build );
140
160
t_user->add_flag (kToolchainTestParam , out.state .test );
141
161
@@ -153,42 +173,42 @@ void Args::AddToolchain(const std::string &name, const std::string &description,
153
173
->default_val (initial.executables .archiver );
154
174
t_user->add_option (kToolchainLinkerParam , out.executables .linker )
155
175
->default_val (initial.executables .linker );
176
+ return *this ;
156
177
}
157
178
158
- void Args::AddTarget (const std::string &name, const std::string &description,
159
- ArgTarget &out, const ArgTarget &initial) {
160
- CLI::App *target_ = args_instance_->target_ ;
161
- env::assert_fatal (target_ != nullptr ,
179
+ /* *
180
+ * @brief Add toolchain with a unique name and description
181
+ *
182
+ * @param out Receive the toolchain information through the CLI
183
+ * @param initial Set the default toolchain information as a fallback
184
+ */
185
+ Args::Instance &Args::Instance::AddTarget (const std::string &name,
186
+ const std::string &description,
187
+ ArgTarget &out,
188
+ const ArgTarget &initial) {
189
+ CLI::App *target = internal_->target ;
190
+ env::assert_fatal (target != nullptr ,
162
191
" Initialize Args using the Args::Init API" );
163
- CLI::App *target_user =
164
- target_ ->add_subcommand (name, description)->group (kTargetGroup );
165
- target_user ->add_option (kTargetCompileCommandParam , out.compile_command )
192
+ CLI::App *targetuser =
193
+ target ->add_subcommand (name, description)->group (kTargetGroup );
194
+ targetuser ->add_option (kTargetCompileCommandParam , out.compile_command )
166
195
->default_val (initial.compile_command );
167
- target_user ->add_option (kTargetLinkCommandParam , out.link_command )
196
+ targetuser ->add_option (kTargetLinkCommandParam , out.link_command )
168
197
->default_val (initial.link_command );
198
+ return *this ;
169
199
}
170
200
171
- // Private
172
-
173
- void Args::RootArgs () {
174
- Ref ().set_help_all_flag (kHelpAllParam , kHelpAllDesc );
175
-
176
- Ref ()
177
- .set_config (kConfigParam , " " , kConfigDesc )
178
- ->expected (kMinFiles , kMaxFiles );
179
-
180
- // Root flags
181
- auto *root_group = Ref ().add_option_group (kRootGroup );
182
-
183
- root_group->add_flag (kCleanParam , clean_, kCleanDesc );
184
- root_group->add_option (kLoglevelParam , loglevel_, kLoglevelDesc )
185
- ->transform (CLI::CheckedTransformer (kLogLevelMap , CLI::ignore_case));
201
+ Args::Instance &Args::Instance::AddCustomCallback (
202
+ const std::function<void (CLI::App &)> &add_cb) {
203
+ auto &app = Ref ();
204
+ add_cb (app);
205
+ return *this ;
206
+ }
186
207
187
- // Dir flags
188
- root_group->add_option (kRootDirParam , project_root_dir_, kRootDirDesc )
189
- ->required ();
190
- root_group->add_option (kBuildDirParam , project_build_dir_, kBuildDirDesc )
191
- ->required ();
208
+ Args::Instance &Args::Instance::AddCustomData (ArgCustom &data) {
209
+ auto &app = Ref ();
210
+ data.Add (app);
211
+ return *this ;
192
212
}
193
213
194
214
} // namespace buildcc
0 commit comments