assemble_core/defaults/tasks/
help.rs1use crate::__export::TaskId;
2use crate::exception::BuildException;
3use crate::project::error::ProjectResult;
4use crate::task::create_task::CreateTask;
5use crate::task::flags::{OptionDeclarationBuilder, OptionDeclarations, OptionsDecoder};
6use crate::task::initialize_task::InitializeTask;
7use crate::task::task_io::TaskIO;
8use crate::task::up_to_date::UpToDate;
9use crate::unstable::text_factory::{
10 less_important_string, list::TextListFactory, AssembleFormatter,
11};
12
13use crate::error::PayloadError;
14use crate::project::finder::{TaskFinder, TaskPath};
15use crate::task::ExecutableTask;
16use crate::{BuildResult, Executable, Project, Task};
17use colored::Colorize;
18use log::info;
19use std::fmt::Write;
20
21#[derive(Debug)]
23pub struct Help {
24 task_request: Option<String>,
25}
26
27impl UpToDate for Help {}
28
29impl InitializeTask for Help {}
30
31impl CreateTask for Help {
32 fn new(_using_id: &TaskId, _project: &Project) -> ProjectResult<Self> {
33 Ok(Self { task_request: None })
34 }
35
36 fn description() -> String {
37 "Print help information for the project using a specific task".to_string()
38 }
39
40 fn only_in_current() -> bool {
41 true
42 }
43
44 fn options_declarations() -> Option<OptionDeclarations> {
45 Some(OptionDeclarations::new::<Help, _>([
46 OptionDeclarationBuilder::<String>::new("task")
47 .optional(true)
48 .use_from_str()
49 .build(),
50 ]))
51 }
52
53 fn try_set_from_decoder(&mut self, decoder: &OptionsDecoder) -> ProjectResult<()> {
54 self.task_request = decoder
55 .get_value::<String>("task")
56 .map_err(|e| PayloadError::new(e))?;
57 Ok(())
58 }
59}
60
61impl TaskIO for Help {}
62
63impl Task for Help {
64 fn task_action(task: &mut Executable<Self>, project: &Project) -> BuildResult {
65 if let Some(_task_request) = &task.task_request {
66 Err(BuildException::custom("help for task requests not implemented").into())
67 } else {
68 let mut text_factory = AssembleFormatter::default();
69
70 writeln!(
71 text_factory.important(),
72 "* Welcome to the assemble builder for {}",
73 project.id()
74 )?;
75 writeln!(text_factory)?;
76 writeln!(
77 text_factory,
78 "To find out what tasks are available for this project, run {}",
79 ":tasks".bold()
80 )?;
81 writeln!(text_factory)?;
82
83 writeln!(
84 text_factory.important(),
85 "* To display more logging information:"
86 )?;
87
88 let list = TextListFactory::new(less_important_string("> ".yellow()))
89 .element("For more detail, run with --debug")
90 .element("For an overwhelming amount of data, run with --trace")
91 .finish();
92
93 write!(text_factory, "{}", list)?;
94
95 info!("{}", text_factory);
96 info!("");
97
98 Ok(())
99 }
100 }
101}