Add verbose cmdline option
Added a verbose cmdline option and moved stdout debug messages there.
This commit is contained in:
parent
8b07320f76
commit
5058545c22
|
@ -116,7 +116,6 @@ namespace Article {
|
||||||
bool reading_article_metadata = false;
|
bool reading_article_metadata = false;
|
||||||
for (std::string const &line : cfg_lines) {
|
for (std::string const &line : cfg_lines) {
|
||||||
if (line == "") continue;
|
if (line == "") continue;
|
||||||
std::cout << "[!] " << line << "\n";
|
|
||||||
// Check namespace
|
// Check namespace
|
||||||
if (reading_article_metadata) {
|
if (reading_article_metadata) {
|
||||||
std::string k_title = "Title=",
|
std::string k_title = "Title=",
|
||||||
|
|
|
@ -61,7 +61,8 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st
|
||||||
// Go ahead and parse article metadata.
|
// Go ahead and parse article metadata.
|
||||||
Article::Metadata *articleMetadata = (Article::Metadata*) malloc(sizeof(Article::Metadata));
|
Article::Metadata *articleMetadata = (Article::Metadata*) malloc(sizeof(Article::Metadata));
|
||||||
Article::get_metadata(a, articleMetadata);
|
Article::get_metadata(a, articleMetadata);
|
||||||
std::cout << "Parsed metadata for article \"" << articleMetadata->title << "\"\n\tPublished on "
|
if (verbose)
|
||||||
|
std::cout << "Parsed metadata for article \"" << articleMetadata->title << "\"\n\tPublished on "
|
||||||
<< ctime(&(articleMetadata->publish_ts)) << "\n";
|
<< ctime(&(articleMetadata->publish_ts)) << "\n";
|
||||||
|
|
||||||
// TODO: This code could be optimized by removing directory
|
// TODO: This code could be optimized by removing directory
|
||||||
|
|
|
@ -91,7 +91,7 @@ std::string get_template(std::string const &path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(swgTemplate);
|
fclose(swgTemplate);
|
||||||
std::cout << "Loaded HTML template into memory.\n";
|
if (verbose) std::cout << "Loaded HTML template into memory.\n";
|
||||||
return htmlTemplate;
|
return htmlTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,3 +51,5 @@ std::string getFilename(std::string const &path, bool const ext = true);
|
||||||
std::filesystem::path get_output_path(std::string const &path);
|
std::filesystem::path get_output_path(std::string const &path);
|
||||||
bool is_special_file(std::string const &filename);
|
bool is_special_file(std::string const &filename);
|
||||||
std::string get_template(std::string const &path);
|
std::string get_template(std::string const &path);
|
||||||
|
|
||||||
|
extern bool verbose;
|
||||||
|
|
|
@ -173,13 +173,12 @@ void build_website(SwgContext &ctx, std::string const &path) {
|
||||||
// Skip all files inside the "output" directory.
|
// Skip all files inside the "output" directory.
|
||||||
if (dir_entry.path().string().find(path + "output/") == 0) continue;
|
if (dir_entry.path().string().find(path + "output/") == 0) continue;
|
||||||
// Directory item iteration
|
// Directory item iteration
|
||||||
std::cout << "\t" << dir_entry << std::endl;
|
if (verbose) std::cout << "\t" << dir_entry << std::endl;
|
||||||
|
|
||||||
// Check if the item is a Markdown file.
|
// Check if the item is a Markdown file.
|
||||||
std::string filename = getFilename(dir_entry.path());
|
std::string filename = getFilename(dir_entry.path());
|
||||||
if (dir_entry.is_regular_file() &&
|
if (dir_entry.is_regular_file() &&
|
||||||
filename.find(".md") == filename.length() - 3) {
|
filename.find(".md") == filename.length() - 3) {
|
||||||
std::cout << "\t\tIs file: " << getFilename(dir_entry.path()) << "\n";
|
|
||||||
// Markdown files should be insite a YYYY/MM directory.
|
// Markdown files should be insite a YYYY/MM directory.
|
||||||
if (!is_valid_article(relativePath, dir_entry.path()))
|
if (!is_valid_article(relativePath, dir_entry.path()))
|
||||||
failedArticles.insert(failedArticles.end(), dir_entry.path());
|
failedArticles.insert(failedArticles.end(), dir_entry.path());
|
||||||
|
|
34
src/main.cxx
34
src/main.cxx
|
@ -33,8 +33,10 @@
|
||||||
#include "Common.hxx"
|
#include "Common.hxx"
|
||||||
#include "WebsiteBuilder.hxx"
|
#include "WebsiteBuilder.hxx"
|
||||||
|
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
void printUsage(const char *programName) {
|
void printUsage(const char *programName) {
|
||||||
std::cerr << programName << ": usage: " << programName << " [path]"
|
std::cerr << programName << ": usage: " << programName << " [options] [path]"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,13 +55,37 @@ int main(int argc, char *argv[]) {
|
||||||
for (int argi = 1; argi < argc; argi++) {
|
for (int argi = 1; argi < argc; argi++) {
|
||||||
if (argv[argi][0] == '-') {
|
if (argv[argi][0] == '-') {
|
||||||
// This is a cmdline option (starts with a dash).
|
// This is a cmdline option (starts with a dash).
|
||||||
|
if (argv[argi][1] == '-') {
|
||||||
|
// Long cmdline option (--example).
|
||||||
|
if (strcmp(argv[argi], "--verbose") == 0) {
|
||||||
|
verbose = true;
|
||||||
|
std::cout << "Verbose output enabled.\n";
|
||||||
|
} else {
|
||||||
|
std::cerr << "error: unknown command line option `" <<
|
||||||
|
argv[argi] << "'." << std::endl;
|
||||||
|
exit(RETURN_FAILED_INVALID_SYNTAX);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i < strlen(argv[argi]); i++) {
|
||||||
|
switch (argv[argi][i]) {
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
std::cout << "Verbose output enabled.\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cerr << "error: unknown command line option `" <<
|
||||||
|
argv[argi] << "'." << std::endl;
|
||||||
|
exit(RETURN_FAILED_INVALID_SYNTAX);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (path == "") {
|
} else if (path == "") {
|
||||||
path = argv[argi];
|
path = argv[argi];
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "error: website directory was already " <<
|
std::cerr << "error: website directory was already " <<
|
||||||
"provided (`" << path << "'), refusing to continue with `" <<
|
"provided (`" << path << "'), refusing to continue with `" <<
|
||||||
argv[argi] << "'.\n";
|
argv[argi] << "'." << std::endl;
|
||||||
printUsage(argv[0]);
|
printUsage(argv[0]);
|
||||||
exit(RETURN_FAILED_INVALID_SYNTAX);
|
exit(RETURN_FAILED_INVALID_SYNTAX);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +98,8 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
build_website(ctx, path);
|
build_website(ctx, path);
|
||||||
|
|
||||||
|
std::cout << "Website build succeeded.\n";
|
||||||
|
|
||||||
// Website blog
|
// Website blog
|
||||||
|
|
||||||
// Append blog to website
|
// Append blog to website
|
||||||
|
|
Loading…
Reference in New Issue