+2
src/cmd/mod.rs
+2
src/cmd/mod.rs
···
7
7
pub mod mkdir;
8
8
pub mod mv;
9
9
pub mod open;
10
+
pub mod print;
10
11
pub mod pwd;
11
12
pub mod random;
12
13
pub mod rm;
···
23
24
pub use mkdir::Mkdir;
24
25
pub use mv::Mv;
25
26
pub use open::Open;
27
+
pub use print::Print;
26
28
pub use pwd::Pwd;
27
29
pub use random::Random;
28
30
pub use rm::Rm;
+47
src/cmd/print.rs
+47
src/cmd/print.rs
···
1
+
use crate::globals::print_to_console;
2
+
use nu_engine::CallExt;
3
+
use nu_protocol::{
4
+
Category, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
5
+
engine::{Command, EngineState, Stack},
6
+
};
7
+
8
+
#[derive(Clone)]
9
+
pub struct Print;
10
+
11
+
impl Command for Print {
12
+
fn name(&self) -> &str {
13
+
"print"
14
+
}
15
+
16
+
fn signature(&self) -> Signature {
17
+
Signature::build("print")
18
+
.rest("rest", SyntaxShape::Any, "values to print")
19
+
.input_output_type(Type::Nothing, Type::Nothing)
20
+
.category(Category::Strings)
21
+
}
22
+
23
+
fn description(&self) -> &str {
24
+
"print values to the console."
25
+
}
26
+
27
+
fn run(
28
+
&self,
29
+
engine_state: &EngineState,
30
+
stack: &mut Stack,
31
+
call: &nu_protocol::engine::Call,
32
+
_input: PipelineData,
33
+
) -> Result<PipelineData, ShellError> {
34
+
let rest: Vec<Value> = call.rest(engine_state, stack, 0)?;
35
+
36
+
let mut parts = Vec::new();
37
+
for value in rest {
38
+
let s = value.to_expanded_string(" ", &engine_state.config);
39
+
parts.push(s);
40
+
}
41
+
let output = parts.join(" ");
42
+
print_to_console(&output, true)?;
43
+
44
+
Ok(PipelineData::Empty)
45
+
}
46
+
}
47
+
+3
-2
src/lib.rs
+3
-2
src/lib.rs
···
28
28
29
29
use crate::{
30
30
cmd::{
31
-
Cd, Fetch, Job, JobKill, JobList, Ls, Mkdir, Mv, Open, Pwd, Random, Rm, Save, Source, Sys,
31
+
Cd, Fetch, Job, JobKill, JobList, Ls, Mkdir, Mv, Open, Print, Pwd, Random, Rm, Save, Source, Sys,
32
32
source::eval_file,
33
33
},
34
34
default_context::add_shell_command_context,
···
102
102
engine_state = add_extra_command_context(engine_state);
103
103
104
104
let mut working_set = StateWorkingSet::new(&engine_state);
105
-
let decls: [Box<dyn Command>; 15] = [
105
+
let decls: [Box<dyn Command>; 16] = [
106
106
Box::new(Ls),
107
107
Box::new(Open),
108
108
Box::new(Save),
···
118
118
Box::new(JobKill),
119
119
Box::new(Sys),
120
120
Box::new(Random),
121
+
Box::new(Print),
121
122
];
122
123
for decl in decls {
123
124
working_set.add_decl(decl);