nushell/crates/nu-command/src/database/commands/collect.rs
Stefan Holderbach 0afe1e4e67
Test command names and search terms for redundancy (#6380)
* Test commands for proper names and search terms

Assert that the `Command.name()` is equal to `Signature.name`

Check that search terms are not just substrings of the command name as
they would not help finding the command.

* Clean up search terms

Remove redundant terms that just replicate the command name.
Try to eliminate substring between search terms, clean up where
necessary.
2022-08-24 11:16:47 +02:00

53 lines
1.3 KiB
Rust

use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type,
};
use super::super::SQLiteDatabase;
#[derive(Clone)]
pub struct CollectDb;
impl Command for CollectDb {
fn name(&self) -> &str {
"collect"
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_type(Type::Custom("database".into()))
.output_type(Type::Any)
.category(Category::Custom("database".into()))
}
fn usage(&self) -> &str {
"Collects a query from a database database connection"
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Collect from a select query",
example: "open foo.db | from table table_1 db | select a | collect",
result: None,
}]
}
fn search_terms(&self) -> Vec<&str> {
vec!["database"]
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let db = SQLiteDatabase::try_from_pipeline(input, call.head)?;
db.collect(call.head)
.map(IntoPipelineData::into_pipeline_data)
}
}