Skip to content
Open
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: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ repository = "https://github.com/sagiegurari/cargo-make.git"
readme = "README.md"
keywords = ["task", "build", "cargo", "plugin", "subcommand"]
categories = [
"command-line-utilities",
"development-tools",
"development-tools::cargo-plugins",
"development-tools::build-utils",
"development-tools::testing",
"command-line-utilities",
"development-tools",
"development-tools::cargo-plugins",
"development-tools::build-utils",
"development-tools::testing",
]
include = [
"/benches/*",
"/docs/*",
"/examples/*",
"/src/*",
"/tests/*",
"/Cargo.toml",
"/LICENSE",
"/README.md",
"/CHANGELOG.md",
"/Makefile.toml",
"/extra/shell/*",
"/benches/*",
"/docs/*",
"/examples/*",
"/src/*",
"/tests/*",
"/Cargo.toml",
"/LICENSE",
"/README.md",
"/CHANGELOG.md",
"/Makefile.toml",
"/extra/shell/*",
]

[lib]
Expand Down
50 changes: 22 additions & 28 deletions src/lib/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::types::Cache;
use fsio::file::{read_text_file, write_text_file};
use std::path::{Path, PathBuf};

static CACHE_FILE: &'static str = "cache.toml";
static CACHE_FILE: &str = "cache.toml";

fn load_from_path(directory: PathBuf) -> Cache {
let file_path = Path::new(&directory).join(CACHE_FILE);
Expand All @@ -33,8 +33,7 @@ fn load_from_path(directory: PathBuf) -> Cache {
Err(error) => {
info!(
"Unable to read cache file: {:?} error: {}",
&file_path,
error.to_string()
&file_path, error
);
Cache::new()
}
Expand Down Expand Up @@ -66,35 +65,30 @@ pub(crate) fn load() -> Cache {

/// Stores the data
pub(crate) fn store(cache_data: &Cache) {
match get_cache_directory(false) {
Some(directory) => {
let exists = if directory.exists() {
true
} else {
match fsio::directory::create(&directory) {
Ok(_) => true,
_ => false,
}
};
if let Some(directory) = get_cache_directory(false) {
let exists = if directory.exists() {
true
} else {
fsio::directory::create(&directory).is_ok()
};

if exists {
let file_name = directory.join(CACHE_FILE);
if exists {
let file_name = directory.join(CACHE_FILE);

match toml::to_string_pretty(cache_data) {
Ok(toml_str) => match write_text_file(&file_name, &toml_str) {
Err(error) => info!(
match toml::to_string_pretty(cache_data) {
Ok(toml_str) => {
if let Err(error) = write_text_file(&file_name, &toml_str) {
info!(
"Error while writing to cache file: {:#?}, error: {:#?}",
&file_name, error
),
_ => (),
},
Err(error) => info!(
"Error during serialization of cache, file: {:#?}, error: {:#?}",
&file_name, error
),
};
}
)
}
}
Err(error) => info!(
"Error during serialization of cache, file: {:#?}, error: {:#?}",
&file_name, error
),
};
}
None => (),
}
}
36 changes: 13 additions & 23 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn run(
debug!("Cli Args {:#?}", &cli_args);
debug!("Global Configuration {:#?}", &global_config);

if version::should_check(&cli_args, &global_config) {
if version::should_check(cli_args, global_config) {
version::check();
}

Expand All @@ -67,21 +67,15 @@ pub fn run(
None => match global_config.search_project_root {
Some(search) => {
if search {
match environment::get_project_root() {
Some(value) => Some(value.clone()),
None => None,
}
environment::get_project_root()
} else {
None
}
}
None => None,
},
};
let cwd = match cwd_string_option {
Some(ref value) => Some(value.as_ref()),
None => None,
};
let cwd = cwd_string_option.as_ref().map(|value| value.as_ref());
let home = environment::setup_cwd(cwd);

let force_makefile = cli_args.build_file.is_some();
Expand All @@ -94,34 +88,30 @@ pub fn run(
.profile
.clone()
.unwrap_or_else(profile::default_profile);
let normalized_profile_name = profile::set(&profile_name);
let normalized_profile_name = profile::set(profile_name);

environment::load_env_file(cli_args.env_file.clone());

let env = cli_args.env.clone();

let experimental = cli_args.experimental;
let config = descriptor::load(&build_file, force_makefile, env, experimental)?;
let config = descriptor::load(build_file, force_makefile, env, experimental)?;

let mut time_summary_vec = vec![];
time_summary::add(
&mut time_summary_vec,
"[Load Makefiles]",
start_time.clone(),
);
time_summary::add(&mut time_summary_vec, "[Load Makefiles]", start_time);
let step_time = SystemTime::now();

match config.config.additional_profiles {
Some(ref profiles) => profile::set_additional(profiles),
None => profile::set_additional(&vec![]),
};

let env_info = environment::setup_env(&cli_args, &config, &task, home, &mut time_summary_vec)?;
let env_info = environment::setup_env(cli_args, &config, task, home, &mut time_summary_vec)?;
time_summary::add(&mut time_summary_vec, "[Setup Env]", step_time);

let crate_name = envmnt::get_or("CARGO_MAKE_CRATE_NAME", "");
info!("");
if crate_name.len() > 0 {
if !crate_name.is_empty() {
info!("Project: {}", &crate_name);
}
info!("Build File: {}", &build_file);
Expand All @@ -144,15 +134,15 @@ pub fn run(
cli_commands::diff_steps::run(
&default_config,
&config,
&task,
&cli_args,
task,
cli_args,
&env_info.crate_info,
)
} else if cli_args.print_only {
cli_commands::print_steps::print(
&mut std::io::stdout(),
&config,
&task,
task,
&cli_args.output_format,
cli_args.disable_workspace,
&cli_args.skip_tasks_pattern,
Expand All @@ -162,9 +152,9 @@ pub fn run(
} else {
runner::run(
config,
&task,
task,
env_info,
&cli_args,
cli_args,
start_time,
time_summary_vec,
)
Expand Down
8 changes: 4 additions & 4 deletions src/lib/cli_commands/diff_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn run(
disable_workspace: cli_args.disable_workspace,
allow_private: true,
skip_tasks_pattern: skip_tasks_pattern.as_ref(),
..ExecutionPlanBuilder::new(internal_config, &task)
..ExecutionPlanBuilder::new(internal_config, task)
}
.build()?;

Expand All @@ -55,16 +55,16 @@ pub(crate) fn run(
disable_workspace: cli_args.disable_workspace,
allow_private: true,
skip_tasks_pattern: skip_tasks_pattern.as_ref(),
..ExecutionPlanBuilder::new(external_config, &task)
..ExecutionPlanBuilder::new(external_config, task)
}
.build()?;

let internal_file = create_file(
&move |file: &mut File| write_as_string(&internal_execution_plan, &file),
&move |file: &mut File| write_as_string(&internal_execution_plan, file),
"toml",
)?;
let external_file = create_file(
&move |file: &mut File| write_as_string(&external_execution_plan, &file),
&move |file: &mut File| write_as_string(&external_execution_plan, file),
"toml",
)?;

Expand Down
26 changes: 11 additions & 15 deletions src/lib/cli_commands/list_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ pub fn run(
category: &Option<String>,
hide_uninteresting: bool,
) -> Result<(), CargoMakeError> {
let output = create_list(&config, output_format, category, hide_uninteresting)?;
let output = create_list(config, output_format, category, hide_uninteresting)?;

match output_file {
Some(file) => {
io::write_text_file(&file, &output);
()
io::write_text_file(file, &output);
}
None => print!("{}", output),
};
Expand All @@ -46,14 +45,11 @@ pub(crate) fn create_list(

// iterate over all tasks to build categories and aliases
for key in config.tasks.keys() {
let actual_task_name = execution_plan::get_actual_task_name(&config, &key)?;
let actual_task_name = execution_plan::get_actual_task_name(config, key)?;

let task = execution_plan::get_normalized_task(&config, &actual_task_name, true)?;
let task = execution_plan::get_normalized_task(config, &actual_task_name, true)?;

let is_private = match task.private {
Some(private) => private,
None => false,
};
let is_private = task.private.unwrap_or(false);

let skip_task = if is_private {
true
Expand All @@ -75,7 +71,7 @@ pub(crate) fn create_list(

if category_filter
.as_ref()
.map_or(false, |value| value != &category)
.is_some_and(|value| value != &category)
{
continue;
}
Expand Down Expand Up @@ -105,15 +101,15 @@ pub(crate) fn create_list(
DeprecationInfo::Message(ref message) => {
let mut buffer = " (deprecated - ".to_string();
buffer.push_str(message);
buffer.push_str(")");
buffer.push(')');

buffer
}
},
None => "".to_string(),
};

let mut text = String::from(description);
let mut text = description;
text.push_str(&deprecated_message);

categories
Expand All @@ -132,14 +128,14 @@ pub(crate) fn create_list(

let mut buffer = String::new();
if single_page_markdown {
buffer.push_str(&format!("# Task List\n\n"));
buffer.push_str("# Task List\n\n");
}

let post_key = if markdown { "**" } else { "" };
for (category, tasks) in &categories {
if category_filter
.as_ref()
.map_or(false, |value| value != category)
.is_some_and(|value| value != category)
{
continue;
}
Expand All @@ -156,7 +152,7 @@ pub(crate) fn create_list(

for (key, description) in tasks {
if markdown {
buffer.push_str(&format!("* **"));
buffer.push_str("* **");
}

let aliases = if let Some(aliases) = aliases.remove(key) {
Expand Down
22 changes: 9 additions & 13 deletions src/lib/cli_commands/print_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ enum PrintFormat {

impl PartialEq for PrintFormat {
fn eq(&self, other: &PrintFormat) -> bool {
match self {
PrintFormat::Default => match other {
PrintFormat::Default => true,
_ => false,
},
PrintFormat::ShortDescription => match other {
PrintFormat::ShortDescription => true,
_ => false,
},
}
matches!(
(self, other),
(PrintFormat::Default, PrintFormat::Default)
| (PrintFormat::ShortDescription, PrintFormat::ShortDescription)
)
}
}

Expand Down Expand Up @@ -62,7 +57,7 @@ fn print_short_description(
counter, &step.name, &description
)?;

counter = counter + 1;
counter += 1;
}
Ok(())
}
Expand All @@ -75,6 +70,7 @@ fn print_default(
}

/// Only prints the execution plan
#[allow(clippy::too_many_arguments)]
pub fn print(
output_buffer: &mut impl io::Write,
config: &Config,
Expand All @@ -101,12 +97,12 @@ pub fn print(
disable_workspace,
skip_tasks_pattern: skip_tasks_pattern_regex.as_ref(),
skip_init_end_tasks,
..ExecutionPlanBuilder::new(&config, &task)
..ExecutionPlanBuilder::new(config, task)
}
.build()?;
debug!("Created execution plan: {:#?}", &execution_plan);

let print_format = get_format_type(&output_format);
let print_format = get_format_type(output_format);

match print_format {
PrintFormat::ShortDescription => print_short_description(output_buffer, &execution_plan)?,
Expand Down
Loading