Skip to content

Commit

Permalink
feat(debug): Generalize debug commands
Browse files Browse the repository at this point in the history
This is making room for more debug commands to be added while making
them selective disclosure.

BREAKING CHANGES: Debug flags have been relocated
- `cobalt --list-syntax-themes` -> `cobalt debug highlight themes`
- `cobalt --list-syntaxes` -> `cobalt debug highlight syntaxes`
  • Loading branch information
epage committed Jan 9, 2018
1 parent bf9d76b commit 087d991
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
36 changes: 36 additions & 0 deletions src/bin/cobalt/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use clap;
use cobalt;

use error::*;

pub fn debug_command_args() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("debug")
.about("Print site debug information")
.subcommand(clap::SubCommand::with_name("highlight")
.about("Print syntax-highlight information")
.subcommand(clap::SubCommand::with_name("themes"))
.subcommand(clap::SubCommand::with_name("syntaxes")))
}

pub fn debug_command(matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
("highlight", Some(matches)) => {
match matches.subcommand() {
("themes", _) => {
for name in cobalt::list_syntax_themes() {
println!("{}", name);
}
}
("syntaxes", _) => {
for name in cobalt::list_syntaxes() {
println!("{}", name);
}
}
_ => bail!(matches.usage()),
}
}
_ => bail!(matches.usage()),
}

Ok(())
}
22 changes: 5 additions & 17 deletions src/bin/cobalt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ extern crate log;
mod args;
mod build;
mod error;
mod debug;
mod jekyll;
mod migrate;
mod new;
mod serve;

use clap::{App, SubCommand, AppSettings};
use cobalt::{list_syntaxes, list_syntax_themes};
use clap::{App, AppSettings};

use error::*;

Expand All @@ -100,10 +100,9 @@ fn run() -> Result<()> {
.subcommand(build::clean_command_args())
.subcommand(serve::serve_command_args())
.subcommand(build::import_command_args())
.subcommand(SubCommand::with_name("list-syntax-themes").about("list available themes"))
.subcommand(SubCommand::with_name("list-syntaxes").about("list supported syntaxes"))
.subcommand(migrate::migrate_command_args())
.subcommand(jekyll::convert_command_args());
.subcommand(jekyll::convert_command_args())
.subcommand(debug::debug_command_args());

let global_matches = app_cli.get_matches();

Expand All @@ -123,18 +122,7 @@ fn run() -> Result<()> {
"clean" => build::clean_command(matches),
"serve" => serve::serve_command(matches),
"import" => build::import_command(matches),
"list-syntax-themes" => {
for name in list_syntax_themes() {
println!("{}", name);
}
Ok(())
}
"list-syntaxes" => {
for name in list_syntaxes() {
println!("{}", name);
}
Ok(())
}
"debug" => debug::debug_command(matches),
"migrate" => migrate::migrate_command(matches),
"convert-jekyll" => jekyll::convert_command(matches),
_ => {
Expand Down

0 comments on commit 087d991

Please sign in to comment.