Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ pub struct PluginArgs {
pub enum PluginSubcommand {
List(PluginListArgs),
Hash(PluginHashArgs),
Verify(PluginVerifyArgs),
}

pub struct PluginListArgs {
pub config: String,
}

pub struct PluginVerifyArgs {
pub config: String,
}

pub struct PluginHashArgs {
pub name: String,
pub plugin_dir: String,
Expand Down Expand Up @@ -96,6 +101,14 @@ impl Default for PluginListArgs {
}
}

impl Default for PluginVerifyArgs {
fn default() -> Self {
Self {
config: DEFAULT_TARS_CONFIG_FILE.to_string(),
}
}
}

fn styles() -> Styles {
Styles::styled()
.header(AnsiColor::BrightGreen.on_default().effects(Effects::BOLD))
Expand Down Expand Up @@ -186,6 +199,18 @@ fn build_cli() -> Command {
)
.about("List installed plugins"),
)
.subcommand(
Command::new("verify")
.arg(
Arg::new("config")
.long("config")
.value_name("CONFIG")
.required(false)
.default_value(DEFAULT_TARS_CONFIG_FILE)
.help("Specify the configuration file to use"),
)
.about("Verify plugin configuration"),
)
.subcommand(
Command::new("hash")
.arg(Arg::new("name").required(true).help("Plugin name"))
Expand Down Expand Up @@ -266,6 +291,13 @@ pub fn parse_args() -> Result<Args> {
plugin_dir: plugin_dir.clone(),
})
}
Some(("verify", args)) => {
let config = args.get_one::<String>("config").unwrap();

PluginSubcommand::Verify(PluginVerifyArgs {
config: config.clone(),
})
}
_ => {
return Err(anyhow!("no subcommand specified"));
}
Expand Down
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async fn main() {

if let Err(e) = init_project(&args, &config) {
println!("Error initializing project: {e}");
exit(1);
} else {
println!("Initialized project in '{}' .", args.path);
}
Expand All @@ -82,21 +83,24 @@ async fn main() {

if let Err(e) = builder.build() {
println!("{e}");
exit(1);
}
}
TarsSubcommand::Clean(args) => {
TarsSubcommand::Clean(args) => {
let config = load_config(&args.config);
let builder = Builder::new(&config, false);

if let Err(e) = builder.clean() {
println!("{e}");
exit(1);
}
}
TarsSubcommand::Serve(args) => {
let config = load_config(&args.config);

if let Err(e) = run_server(Arc::new(config)).await {
println!("{e}");
exit(1);
}
}
TarsSubcommand::Plugin(args) => match args.subcommand {
Expand All @@ -107,6 +111,18 @@ async fn main() {
println!("Name: {}, Hook: {:#?}", p.name, p.hook_type);
}
}
PluginSubcommand::Verify(args) => {
let config = load_config(&args.config);

for p in config.plugins {
if let Err(e) = p.resolve(Path::new(&config.build.plugin_dir), false) {
println!("Verification failed for {}: {}", p.name, e);
exit(1);
} else {
println!("Verification success for {}", p.name);
}
}
}
PluginSubcommand::Hash(args) => {
// The actual values don't matter hare, as long as `name` is correct
let plugin = Plugin {
Expand All @@ -121,6 +137,7 @@ async fn main() {
}
Err(e) => {
println!("Error while calculating digest: {e}");
exit(1);
}
}
}
Expand Down