Skip to content

Commit

Permalink
- improved help output
Browse files Browse the repository at this point in the history
  • Loading branch information
GloryOfNight committed Nov 16, 2023
1 parent b081895 commit 7299d49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ int main(int argc, char* argv[], char* envp[])
log(DISPLAY, "Available arguments list:");
for (auto& arg : args)
{
log(DISPLAY, "\t[%s] %s", arg.name.data(), arg.note.data());
if (arg.note_help.size() == 0)
continue;

log(DISPLAY, "%s", arg.note_help.data());
}

log(DISPLAY, "\nSource code page: https://github.com/GloryOfNight/clang-format-all.git");
Expand Down Expand Up @@ -200,7 +203,10 @@ void parseArgs(int argc, char* argv[])
}
else
{
log(ERROR, "Unknown argument: %s", arg);
if (arg.ends_with("clang-format-all") || arg.ends_with("clang-format-all.exe"))
continue;

log(ERROR, "Unknown argument: %s", arg.data());
}
}
}
Expand All @@ -216,10 +222,10 @@ void parseEnvp(char* envp[])
const auto found_env = std::find_if(std::begin(env_vars), std::end(env_vars), [&env_name](const val_ref& val)
{ return val.name == env_name; });

// if env variable found
// separate variable from it's contents
// check if env_var we found are supported type
// save contents to env
// if found_env variable found
// separate env variable from it's contents
// check if found_env are supported type
// save contents to found_env
if (found_env != std::end(env_vars))
{
const std::string_view env_value = env.substr(env.find_first_of('=') + 1);
Expand Down
22 changes: 11 additions & 11 deletions src/statics.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
struct val_ref // helper struct to improve workflow for command line arguments
{
template <typename T>
constexpr val_ref(const std::string_view& inName, const std::string_view& inNote, T& inValue)
constexpr val_ref(const std::string_view& inName, T& inValue, const std::string_view& inNoteHelp)
: name{inName}
, note{inNote}
, note_help{inNoteHelp}
, value{&inValue}
, type{typeid(T)}
{
}

std::string_view name;
std::string_view note;
std::string_view note_help;
void* value;
const std::type_info& type;

Expand All @@ -40,21 +40,21 @@ static std::vector<std::filesystem::path> ignorePaths{}; // paths to ignore with
// clang-format off
static constexpr auto args = std::array
{
val_ref{"--help", "print help", printHelp},
val_ref{"--no-logs", "disable logs (might improve performance slightly)", logPrintNone},
val_ref{"--verbose", "enable verbose logs", logPrintVerbose},
val_ref{"-S", "source directory to format", sourceDir},
val_ref{"-E", "clang-format executable path", formatExecPath},
val_ref{"-I", "space separated list of paths to ignore relative to [-S]", ignorePaths},
val_ref{"-C", "additional command-line arguments for clang-format executable", formatCommands}
val_ref{"--help", printHelp, "--help = print help" },
val_ref{"--no-logs", logPrintNone, "--no-logs = disable logs (might improve performance slightly)" },
val_ref{"--verbose", logPrintVerbose, "--verbose = enable verbose logs" },
val_ref{"-S", sourceDir, "-S <path-to-source> = directory to format" },
val_ref{"-E", formatExecPath, "-E <path-to-clang-format> = clang-format executable path" },
val_ref{"-I", ignorePaths, "-I <dirs-list> = list of paths to ignore relative to -S" },
val_ref{"-C", formatCommands, "-C <args-clang-format> = additional command-line arguments for clang-format executable" }
};
// clang-format on

static std::string_view llvm;
// clang-format off
static constexpr auto env_vars = std::array
{
val_ref{"LLVM","", llvm}
val_ref{"LLVM", llvm, ""}
};
// clang-format on

Expand Down

0 comments on commit 7299d49

Please sign in to comment.