Repository navigation
feat(driver): one subcommand per translation unit #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "driver/driver.h" | ||
|
|
||
| namespace clice::driver { | ||
|
|
||
| namespace { | ||
|
|
||
| struct DocOptions { | ||
| DecoFlag(names = {"-h", "--help"}, help = "Show help", required = false) | ||
| help; | ||
| }; | ||
|
|
||
| auto make_command() { | ||
| return kota::deco::cli::command<DocOptions>("clice doc [OPTIONS]"); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void add_doc(kota::deco::cli::SubCommander& root, int& exit_code) { | ||
| auto cmd = make_command(); | ||
| cmd.matchAll([&exit_code](DocOptions opts) { | ||
| if(opts.help) { | ||
| auto help = make_command(); | ||
| print_usage(help); | ||
| exit_code = 0; | ||
| return; | ||
| } | ||
| std::println( | ||
| stderr, | ||
| "clice doc is not implemented yet: it will generate documentation data for the workspace."); | ||
| }) | ||
| .on_error([](auto err) { LOG_ERROR("{}", err.message); }); | ||
|
|
||
| root.add({.name = "doc", .description = "Generate documentation data"}, std::move(cmd)); | ||
| } | ||
|
|
||
| } // namespace clice::driver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #pragma once | ||
|
|
||
| #include <print> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| #include "support/logging.h" | ||
|
|
||
| #include "kota/deco/deco.h" | ||
|
|
||
| namespace clice::driver { | ||
|
|
||
| /// Each subcommand lives in its own translation unit under src/driver/ and | ||
| /// registers itself with the root commander through one of these builders. | ||
| /// `exit_code` is written by the matched handler when the command runs; | ||
| /// clice.cc owns the commander and the final process exit. | ||
|
|
||
| void add_serve(kota::deco::cli::SubCommander& root, int& exit_code, const char* self_path); | ||
| void add_query(kota::deco::cli::SubCommander& root, int& exit_code); | ||
| void add_worker(kota::deco::cli::SubCommander& root, int& exit_code); | ||
| void add_index(kota::deco::cli::SubCommander& root, int& exit_code); | ||
| void add_doc(kota::deco::cli::SubCommander& root, int& exit_code); | ||
| void add_lint(kota::deco::cli::SubCommander& root, int& exit_code); | ||
| void add_format(kota::deco::cli::SubCommander& root, int& exit_code); | ||
|
|
||
| /// Set the global log level from a user-supplied string; complains and | ||
| /// returns false on an unknown level. | ||
| inline bool apply_log_level(const std::string& level_str) { | ||
| auto level = spdlog::level::from_str(level_str); | ||
| if(level == spdlog::level::off && level_str != "off") { | ||
| std::println(stderr, | ||
| "unknown log level '{}', valid: trace, debug, info, warn, error, off", | ||
| level_str); | ||
| return false; | ||
| } | ||
| logging::options.level = level; | ||
| return true; | ||
| } | ||
|
|
||
| template <typename Command> | ||
| void print_usage(Command& cmd) { | ||
| std::ostringstream ss; | ||
| cmd.usage(ss); | ||
| std::print("{}", ss.str()); | ||
| } | ||
|
|
||
| } // namespace clice::driver | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "driver/driver.h" | ||
|
|
||
| namespace clice::driver { | ||
|
|
||
| namespace { | ||
|
|
||
| struct FormatOptions { | ||
| DecoFlag(names = {"-h", "--help"}, help = "Show help", required = false) | ||
| help; | ||
| }; | ||
|
|
||
| auto make_command() { | ||
| return kota::deco::cli::command<FormatOptions>("clice format [OPTIONS]"); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void add_format(kota::deco::cli::SubCommander& root, int& exit_code) { | ||
| auto cmd = make_command(); | ||
| cmd.matchAll([&exit_code](FormatOptions opts) { | ||
| if(opts.help) { | ||
| auto help = make_command(); | ||
| print_usage(help); | ||
| exit_code = 0; | ||
| return; | ||
| } | ||
| std::println(stderr, | ||
| "clice format is not implemented yet: it will format C++ source files."); | ||
| }) | ||
| .on_error([](auto err) { LOG_ERROR("{}", err.message); }); | ||
|
|
||
| root.add({.name = "format", .description = "Format C++ source files"}, std::move(cmd)); | ||
| } | ||
|
|
||
| } // namespace clice::driver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "driver/driver.h" | ||
|
|
||
| namespace clice::driver { | ||
|
|
||
| namespace { | ||
|
|
||
| struct IndexOptions { | ||
| DecoFlag(names = {"-h", "--help"}, help = "Show help", required = false) | ||
| help; | ||
| }; | ||
|
|
||
| auto make_command() { | ||
| return kota::deco::cli::command<IndexOptions>("clice index [OPTIONS]"); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void add_index(kota::deco::cli::SubCommander& root, int& exit_code) { | ||
| auto cmd = make_command(); | ||
| cmd.matchAll([&exit_code](IndexOptions opts) { | ||
| if(opts.help) { | ||
| auto help = make_command(); | ||
| print_usage(help); | ||
| exit_code = 0; | ||
| return; | ||
| } | ||
| std::println( | ||
| stderr, | ||
| "clice index is not implemented yet: it will build the workspace symbol index ahead of time."); | ||
| }) | ||
| .on_error([](auto err) { LOG_ERROR("{}", err.message); }); | ||
|
|
||
| root.add({.name = "index", .description = "Index a workspace ahead of time"}, std::move(cmd)); | ||
| } | ||
|
|
||
| } // namespace clice::driver |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.