Skip to content

Commit e3a682d

Browse files
authored
#1268: allow datafusion-cli to toggle quiet flag within CLI (#1330)
* #1268: allow datafusion-cli to toggle quiet flag within CLI * Implement quiet_mode in command
1 parent 301e863 commit e3a682d

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

datafusion-cli/src/command.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ pub enum Command {
3737
DescribeTable(String),
3838
ListFunctions,
3939
SearchFunctions(String),
40+
QuietMode(bool),
4041
}
4142

4243
impl Command {
4344
pub async fn execute(
4445
&self,
4546
ctx: &mut Context,
46-
print_options: &PrintOptions,
47+
print_options: &mut PrintOptions,
4748
) -> Result<()> {
4849
let now = Instant::now();
4950
match self {
@@ -64,6 +65,10 @@ impl Command {
6465
.print_batches(&batches, now)
6566
.map_err(|e| DataFusionError::Execution(e.to_string()))
6667
}
68+
Self::QuietMode(quiet) => {
69+
print_options.quiet = *quiet;
70+
Ok(())
71+
}
6772
Self::Quit => Err(DataFusionError::Execution(
6873
"Unexpected quit, this should be handled outside".into(),
6974
)),
@@ -89,17 +94,19 @@ impl Command {
8994
Self::Help => ("\\?", "help"),
9095
Self::ListFunctions => ("\\h", "function list"),
9196
Self::SearchFunctions(_) => ("\\h function", "search function"),
97+
Self::QuietMode(_) => ("\\quiet", "set quiet mode"),
9298
}
9399
}
94100
}
95101

96-
const ALL_COMMANDS: [Command; 6] = [
102+
const ALL_COMMANDS: [Command; 7] = [
97103
Command::ListTables,
98104
Command::DescribeTable(String::new()),
99105
Command::Quit,
100106
Command::Help,
101107
Command::ListFunctions,
102108
Command::SearchFunctions(String::new()),
109+
Command::QuietMode(false),
103110
];
104111

105112
fn all_commands_info() -> RecordBatch {
@@ -137,6 +144,7 @@ impl FromStr for Command {
137144
("?", None) => Self::Help,
138145
("h", None) => Self::ListFunctions,
139146
("h", Some(function)) => Self::SearchFunctions(function.into()),
147+
("quiet", Some(b)) => Self::QuietMode(b == "true"),
140148
_ => return Err(()),
141149
})
142150
}

datafusion-cli/src/exec.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
8484
rl.set_helper(Some(CliHelper::default()));
8585
rl.load_history(".history").ok();
8686

87+
let mut print_options = print_options.clone();
88+
8789
loop {
8890
match rl.readline("❯ ") {
8991
Ok(line) if line.starts_with('\\') => {
@@ -92,7 +94,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
9294
match cmd {
9395
Command::Quit => break,
9496
_ => {
95-
if let Err(e) = cmd.execute(ctx, print_options).await {
97+
if let Err(e) = cmd.execute(ctx, &mut print_options).await {
9698
eprintln!("{}", e)
9799
}
98100
}
@@ -103,7 +105,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
103105
}
104106
Ok(line) => {
105107
rl.add_history_entry(line.trim_end());
106-
match exec_and_print(ctx, print_options, line).await {
108+
match exec_and_print(ctx, &print_options, line).await {
107109
Ok(_) => {}
108110
Err(err) => eprintln!("{:?}", err),
109111
}

docs/source/user-guide/cli.md

+34
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,37 @@ The DataFusion CLI can also connect to a Ballista scheduler for query execution.
7272
```bash
7373
datafusion-cli --host localhost --port 50050
7474
```
75+
76+
## Cli commands
77+
78+
Available commands inside DataFusion CLI are:
79+
80+
- Quit
81+
82+
```bash
83+
> \q
84+
```
85+
86+
- Help
87+
88+
```bash
89+
> \?
90+
```
91+
92+
- ListTables
93+
94+
```bash
95+
> \d
96+
```
97+
98+
- DescribeTable
99+
100+
```bash
101+
> \d table_name
102+
```
103+
104+
- QuietMode
105+
106+
```
107+
> \quiet [true|false]
108+
```

0 commit comments

Comments
 (0)