Apache DataFusion SQL Query Engine
#1268: allow datafusion-cli to toggle quiet flag within CLI (#1330)
Javier Godaye3a682d732f6
diff --git a/datafusion-cli/src/command.rs b/datafusion-cli/src/command.rsindex 3b4d1c566a..39cd5e93cd 100644--- a/datafusion-cli/src/command.rs+++ b/datafusion-cli/src/command.rs@@ -37,13 +37,14 @@ pub enum Command {DescribeTable(String),ListFunctions,SearchFunctions(String),+ QuietMode(bool),}impl Command {pub async fn execute(&self,ctx: &mut Context,- print_options: &PrintOptions,+ print_options: &mut PrintOptions,) -> Result<()> {let now = Instant::now();match self {@@ -64,6 +65,10 @@ impl Command {.print_batches(&batches, now).map_err(|e| DataFusionError::Execution(e.to_string()))}+ Self::QuietMode(quiet) => {+ print_options.quiet = *quiet;+ Ok(())+ }Self::Quit => Err(DataFusionError::Execution("Unexpected quit, this should be handled outside".into(),)),@@ -89,17 +94,19 @@ impl Command {Self::Help => ("\\?", "help"),Self::ListFunctions => ("\\h", "function list"),Self::SearchFunctions(_) => ("\\h function", "search function"),+ Self::QuietMode(_) => ("\\quiet", "set quiet mode"),}}}-const ALL_COMMANDS: [Command; 6] = [+const ALL_COMMANDS: [Command; 7] = [Command::ListTables,Command::DescribeTable(String::new()),Command::Quit,Command::Help,Command::ListFunctions,Command::SearchFunctions(String::new()),+ Command::QuietMode(false),];fn all_commands_info() -> RecordBatch {@@ -137,6 +144,7 @@ impl FromStr for Command {("?", None) => Self::Help,("h", None) => Self::ListFunctions,("h", Some(function)) => Self::SearchFunctions(function.into()),+ ("quiet", Some(b)) => Self::QuietMode(b == "true"),_ => return Err(()),})}diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rsindex 103dd72a00..41db7e6ead 100644--- a/datafusion-cli/src/exec.rs+++ b/datafusion-cli/src/exec.rs@@ -84,6 +84,8 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {rl.set_helper(Some(CliHelper::default()));rl.load_history(".history").ok();+ let mut print_options = print_options.clone();+loop {match rl.readline("❯ ") {Ok(line) if line.starts_with('\\') => {@@ -92,7 +94,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {match cmd {Command::Quit => break,_ => {- if let Err(e) = cmd.execute(ctx, print_options).await {+ if let Err(e) = cmd.execute(ctx, &mut print_options).await {eprintln!("{}", e)}}@@ -103,7 +105,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {}Ok(line) => {rl.add_history_entry(line.trim_end());- match exec_and_print(ctx, print_options, line).await {+ match exec_and_print(ctx, &print_options, line).await {Ok(_) => {}Err(err) => eprintln!("{:?}", err),}diff --git a/docs/source/user-guide/cli.md b/docs/source/user-guide/cli.mdindex cb95fba511..049573f6d2 100644--- a/docs/source/user-guide/cli.md+++ b/docs/source/user-guide/cli.md@@ -72,3 +72,37 @@ The DataFusion CLI can also connect to a Ballista scheduler for query execution.```bashdatafusion-cli --host localhost --port 50050```++## Cli commands++Available commands inside DataFusion CLI are:++- Quit++```bash+> \q+```++- Help++```bash+> \?+```++- ListTables++```bash+> \d+```++- DescribeTable++```bash+> \d table_name+```++- QuietMode++```+> \quiet [true|false]+```