Remove unused code

Closes #467
This commit is contained in:
Yehuda Katz 2019-09-01 23:11:05 -07:00
parent 246c9c06dc
commit 7fa09f59c2
28 changed files with 30 additions and 318 deletions

View File

@ -323,12 +323,6 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
LineResult::Break => {
break;
}
LineResult::FatalError(_, err) => {
context.with_host(|host| {
host.stdout(&format!("A surprising fatal error occurred.\n{:?}", err))
});
}
}
ctrlcbreak = false;
}
@ -344,9 +338,6 @@ enum LineResult {
Error(String, ShellError),
CtrlC,
Break,
#[allow(unused)]
FatalError(String, ShellError),
}
async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context) -> LineResult {

View File

@ -1,17 +1,8 @@
use crate::object::Value;
#[allow(unused)]
#[derive(Debug)]
pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
Fatal,
}
pub enum LogLevel {}
#[allow(unused)]
#[derive(Debug)]
pub struct LogItem {
level: LogLevel,

View File

@ -84,17 +84,6 @@ pub(crate) enum ClassifiedCommand {
External(ExternalCommand),
}
impl ClassifiedCommand {
#[allow(unused)]
pub fn span(&self) -> Span {
match self {
ClassifiedCommand::Expr(token) => token.span(),
ClassifiedCommand::Internal(internal) => internal.name_span.into(),
ClassifiedCommand::External(external) => external.name_span.into(),
}
}
}
pub(crate) struct InternalCommand {
pub(crate) command: Arc<Command>,
pub(crate) name_span: Span,
@ -199,7 +188,7 @@ impl InternalCommand {
pub(crate) struct ExternalCommand {
pub(crate) name: String,
#[allow(unused)]
pub(crate) name_span: Span,
pub(crate) args: Vec<Tagged<String>>,
}

View File

@ -148,10 +148,6 @@ impl CommandArgs {
))
}
// pub fn name_span(&self) -> Span {
// self.call_info.name_span
// }
pub fn process<'de, T: Deserialize<'de>>(
self,
registry: &CommandRegistry,
@ -235,11 +231,6 @@ pub struct RunnableContext {
}
impl RunnableContext {
#[allow(unused)]
pub fn cwd(&self) -> PathBuf {
PathBuf::from(self.shell_manager.path())
}
pub fn expect_command(&self, name: &str) -> Arc<Command> {
self.commands
.get_command(name)
@ -337,8 +328,6 @@ impl EvaluatedWholeStreamCommandArgs {
#[get = "pub"]
pub struct EvaluatedFilterCommandArgs {
args: EvaluatedCommandArgs,
#[allow(unused)]
input: Tagged<Value>,
}
impl Deref for EvaluatedFilterCommandArgs {
@ -353,7 +342,6 @@ impl EvaluatedFilterCommandArgs {
host: Arc<Mutex<dyn Host>>,
shell_manager: ShellManager,
call_info: CallInfo,
input: Tagged<Value>,
) -> EvaluatedFilterCommandArgs {
EvaluatedFilterCommandArgs {
args: EvaluatedCommandArgs {
@ -361,7 +349,6 @@ impl EvaluatedFilterCommandArgs {
shell_manager,
call_info,
},
input,
}
}
}
@ -404,7 +391,6 @@ impl EvaluatedCommandArgs {
}
}
#[allow(unused)]
pub fn has(&self, name: &str) -> bool {
self.call_info.args.has(name)
}
@ -624,7 +610,6 @@ impl Command {
}
}
#[allow(unused)]
pub struct FnFilterCommand {
name: String,
func: fn(EvaluatedFilterCommandArgs) -> Result<OutputStream, ShellError>,
@ -658,16 +643,13 @@ impl WholeStreamCommand for FnFilterCommand {
let result = input.values.map(move |it| {
let registry = registry.clone();
let call_info = match call_info
.clone()
.evaluate(&registry, &Scope::it_value(it.clone()))
{
let call_info = match call_info.clone().evaluate(&registry, &Scope::it_value(it)) {
Err(err) => return OutputStream::from(vec![Err(err)]).values,
Ok(args) => args,
};
let args =
EvaluatedFilterCommandArgs::new(host.clone(), shell_manager.clone(), call_info, it);
EvaluatedFilterCommandArgs::new(host.clone(), shell_manager.clone(), call_info);
match func(args) {
Err(err) => return OutputStream::from(vec![Err(err)]).values,
@ -689,14 +671,3 @@ pub fn whole_stream_command(command: impl WholeStreamCommand + 'static) -> Arc<C
pub fn per_item_command(command: impl PerItemCommand + 'static) -> Arc<Command> {
Arc::new(Command::PerItem(Arc::new(command)))
}
#[allow(unused)]
pub fn filter(
name: &str,
func: fn(EvaluatedFilterCommandArgs) -> Result<OutputStream, ShellError>,
) -> Arc<Command> {
Arc::new(Command::WholeStream(Arc::new(FnFilterCommand {
name: name.to_string(),
func,
})))
}

View File

@ -60,7 +60,6 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
Some(v) => Ok(v.clone()),
None => Ok(Value::nothing().tagged(obj.tag)),
}
// Ok(current.clone())
}
pub fn get(

View File

@ -16,8 +16,7 @@ impl WholeStreamCommand for Last {
}
fn signature(&self) -> Signature {
Signature::build("last")
.required("amount", SyntaxType::Number)
Signature::build("last").required("amount", SyntaxType::Number)
}
fn usage(&self) -> &str {
@ -30,7 +29,6 @@ impl WholeStreamCommand for Last {
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, last)?.run()
// last(args, registry)
}
}

View File

@ -1,11 +1,4 @@
#[doc(hidden)]
#[allow(unused)]
macro_rules! named_type {
($name:ident) => {
$crate::parser::registry::NamedType::$($name)*
}
}
#[macro_export]
macro_rules! command {
(
@ -356,39 +349,4 @@ macro_rules! command {
}
);
};
// ($export:ident as $name:tt ( $args:ident, -- $param:ident : $kind:ident ) $body:block) => {
// #[allow(non_camel_case_types)]
// pub struct $export;
// impl Command for $export {
// fn run(&self, $args: CommandArgs) -> Result<OutputStream, ShellError> {
// fn command($args: CommandArgs, $param: $kind) -> Result<OutputStream, ShellError> {
// $body
// }
// use std::convert::TryInto;
// let param = $args.get(stringify!($param)).try_into()?;
// command($args, param)
// }
// fn name(&self) -> &str {
// stringify!($name)
// }
// fn config(&self) -> Signature {
// let mut named: IndexMap<String, NamedType> = IndexMap::new();
// named.insert(stringify!($param).to_string(), NamedType::$kind);
// Signature {
// name: self.name().to_string(),
// mandatory_positional: vec![],
// optional_positional: vec![],
// rest_positional: false,
// named,
// }
// }
// }
// };
}

View File

@ -294,7 +294,6 @@ pub fn sink_plugin(
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
//use subprocess::Exec;
let args = args.evaluate_once(registry)?;
let call_info = args.call_info.clone();

View File

@ -63,7 +63,6 @@ fn run(
file => file.clone(),
};
let path_str = path.as_string()?;
//let body_str = body.as_string()?;
let path_span = path.span();
let has_raw = call_info.args.has("raw");
let user = call_info.args.get("user").map(|x| x.as_string().unwrap());

View File

@ -1,4 +1,3 @@
#[allow(unused)]
use crate::prelude::*;
use ansi_term::Color;
@ -436,24 +435,6 @@ pub struct ShellDiagnostic {
pub(crate) diagnostic: Diagnostic<Span>,
}
impl ShellDiagnostic {
#[allow(unused)]
pub(crate) fn simple_diagnostic(
span: impl Into<Span>,
source: impl Into<String>,
) -> ShellDiagnostic {
use language_reporting::*;
let span = span.into();
let source = source.into();
let diagnostic =
Diagnostic::new(Severity::Error, "Parse error").with_label(Label::new_primary(span));
ShellDiagnostic { diagnostic }
}
}
impl PartialEq for ShellDiagnostic {
fn eq(&self, _other: &ShellDiagnostic) -> bool {
false

View File

@ -7,8 +7,7 @@ pub(crate) mod vtable;
use crate::prelude::*;
pub(crate) use entries::EntriesView;
#[allow(unused)]
pub(crate) use generic::GenericView;
pub(crate) use table::TableView;
pub(crate) use vtable::VTableView;

View File

@ -3,7 +3,7 @@ use crate::prelude::*;
use derive_new::new;
// A list is printed one line at a time with an optional separator between groups
#[allow(unused)]
#[derive(new)]
pub struct ListView {
list: Vec<Vec<String>>,

View File

@ -25,6 +25,7 @@ pub use crate::commands::command::{CallInfo, ReturnSuccess, ReturnValue};
pub use crate::context::{SourceMap, SpanSource};
pub use crate::env::host::BasicHost;
pub use crate::parser::hir::SyntaxType;
pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
pub use crate::plugin::{serve_plugin, Plugin};
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
pub use cli::cli;

View File

@ -7,8 +7,7 @@ pub(crate) mod into;
pub(crate) mod meta;
pub(crate) mod types;
#[allow(unused)]
pub(crate) use base::{Block, Primitive, Switch, Value};
pub(crate) use dict::{Dictionary, TaggedListBuilder, TaggedDictBuilder};
pub(crate) use files::dir_entry_dict;
pub(crate) use base::{Primitive, Value};
pub(crate) use command::command_dict;
pub(crate) use dict::{Dictionary, TaggedDictBuilder, TaggedListBuilder};
pub(crate) use files::dir_entry_dict;

View File

@ -174,7 +174,7 @@ pub enum Value {
#[serde(with = "serde_bytes")]
Binary(Vec<u8>),
List(Vec<Tagged<Value>>),
#[allow(unused)]
Block(Block),
}
@ -313,16 +313,6 @@ pub enum Switch {
Absent,
}
impl Switch {
#[allow(unused)]
pub fn is_present(&self) -> bool {
match self {
Switch::Present => true,
Switch::Absent => false,
}
}
}
impl std::convert::TryFrom<Option<&Tagged<Value>>> for Switch {
type Error = ShellError;
@ -395,14 +385,6 @@ impl Value {
}
}
#[allow(unused)]
pub(crate) fn get_data_by_index(&self, idx: usize) -> Option<&Tagged<Value>> {
match self {
Value::List(l) => l.iter().nth(idx),
_ => None,
}
}
pub fn get_data_by_path(&self, tag: Tag, path: &str) -> Option<Tagged<&Value>> {
let mut current = self;
for p in path.split(".") {
@ -539,7 +521,6 @@ impl Value {
}
}
#[allow(unused)]
pub(crate) fn compare(
&self,
operator: &Operator,
@ -570,24 +551,6 @@ impl Value {
}
}
#[allow(unused)]
pub(crate) fn is_string(&self, expected: &str) -> bool {
match self {
Value::Primitive(Primitive::String(s)) if s == expected => true,
other => false,
}
}
// pub(crate) fn as_pair(&self) -> Result<(Tagged<Value>, Tagged<Value>), ShellError> {
// match self {
// Value::List(list) if list.len() == 2 => Ok((list[0].clone(), list[1].clone())),
// other => Err(ShellError::string(format!(
// "Expected pair, got {:?}",
// other
// ))),
// }
// }
pub(crate) fn as_string(&self) -> Result<String, ShellError> {
match self {
Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
@ -647,7 +610,6 @@ impl Value {
Value::Primitive(Primitive::Date(s.into()))
}
#[allow(unused)]
pub fn date_from_str(s: &str) -> Result<Value, ShellError> {
let date = DateTime::parse_from_rfc3339(s)
.map_err(|err| ShellError::string(&format!("Date parse error: {}", err)))?;
@ -705,95 +667,6 @@ pub(crate) fn reject_fields(obj: &Value, fields: &[String], tag: impl Into<Tag>)
out.into_tagged_value()
}
#[allow(unused)]
pub(crate) fn find(obj: &Value, field: &str, op: &Operator, rhs: &Value) -> bool {
let descs = obj.data_descriptors();
match descs.iter().find(|d| *d == field) {
None => false,
Some(desc) => {
let v = obj.get_data(desc).borrow().clone();
match v {
Value::Primitive(Primitive::Boolean(b)) => match (op, rhs) {
(Operator::Equal, Value::Primitive(Primitive::Boolean(b2))) => b == *b2,
(Operator::NotEqual, Value::Primitive(Primitive::Boolean(b2))) => b != *b2,
_ => false,
},
Value::Primitive(Primitive::Bytes(i)) => match (op, rhs) {
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) < *i2
}
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) > *i2
}
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) <= *i2
}
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) >= *i2
}
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) == *i2
}
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => {
BigInt::from(i) != *i2
}
_ => false,
},
Value::Primitive(Primitive::Int(i)) => match (op, rhs) {
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => i < *i2,
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => i > *i2,
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => i <= *i2,
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
i >= *i2
}
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => i == *i2,
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => i != *i2,
_ => false,
},
Value::Primitive(Primitive::Decimal(i)) => match (op, rhs) {
(Operator::LessThan, Value::Primitive(Primitive::Decimal(i2))) => i < *i2,
(Operator::GreaterThan, Value::Primitive(Primitive::Decimal(i2))) => i > *i2,
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Decimal(i2))) => {
i <= *i2
}
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Decimal(i2))) => {
i >= *i2
}
(Operator::Equal, Value::Primitive(Primitive::Decimal(i2))) => i == *i2,
(Operator::NotEqual, Value::Primitive(Primitive::Decimal(i2))) => i != *i2,
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => {
i < BigDecimal::from(i2.clone())
}
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => {
i > BigDecimal::from(i2.clone())
}
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
i <= BigDecimal::from(i2.clone())
}
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
i >= BigDecimal::from(i2.clone())
}
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => {
i == BigDecimal::from(i2.clone())
}
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => {
i != BigDecimal::from(i2.clone())
}
_ => false,
},
Value::Primitive(Primitive::String(s)) => match (op, rhs) {
(Operator::Equal, Value::Primitive(Primitive::String(s2))) => s == *s2,
(Operator::NotEqual, Value::Primitive(Primitive::String(s2))) => s != *s2,
_ => false,
},
_ => false,
}
}
}
}
enum CompareValues {
Ints(BigInt, BigInt),
Decimals(BigDecimal, BigDecimal),

View File

@ -92,7 +92,6 @@ pub enum RawExpression {
FilePath(PathBuf),
ExternalCommand(ExternalCommand),
#[allow(unused)]
Boolean(bool),
}

View File

@ -33,7 +33,7 @@ pub fn baseline_parse_tokens(
Ok(exprs)
}
#[allow(unused)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum SyntaxType {
Any,

View File

@ -20,7 +20,7 @@ impl ToDebug for Operator {
}
impl Operator {
#[allow(unused)]
pub fn print(&self) -> String {
self.as_str().to_string()
}

View File

@ -678,6 +678,8 @@ mod tests {
use crate::parser::parse::token_tree_builder::{CurriedToken, TokenTreeBuilder};
use pretty_assertions::assert_eq;
pub type CurriedNode<T> = Box<dyn FnOnce(&mut TokenTreeBuilder) -> T + 'static>;
macro_rules! assert_leaf {
(parsers [ $($name:tt)* ] $input:tt -> $left:tt .. $right:tt { $kind:tt $parens:tt } ) => {
$(

View File

@ -9,7 +9,7 @@ use std::fmt;
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum TokenNode {
Token(Token),
#[allow(unused)]
Call(Tagged<CallNode>),
Delimited(Tagged<DelimitedNode>),
Pipeline(Tagged<Pipeline>),
@ -17,7 +17,7 @@ pub enum TokenNode {
Flag(Tagged<Flag>),
Member(Span),
Whitespace(Span),
#[allow(unused)]
Error(Tagged<Box<ShellError>>),
Path(Tagged<PathNode>),
}

View File

@ -1,4 +1,3 @@
#[allow(unused)]
use crate::prelude::*;
use crate::parser::parse::flag::{Flag, FlagKind};
@ -17,12 +16,9 @@ pub struct TokenTreeBuilder {
pos: usize,
}
#[allow(unused)]
pub type CurriedNode<T> = Box<dyn FnOnce(&mut TokenTreeBuilder) -> T + 'static>;
pub type CurriedToken = Box<dyn FnOnce(&mut TokenTreeBuilder) -> TokenNode + 'static>;
pub type CurriedCall = Box<dyn FnOnce(&mut TokenTreeBuilder) -> Tagged<CallNode> + 'static>;
#[allow(unused)]
impl TokenTreeBuilder {
pub fn build(block: impl FnOnce(&mut Self) -> TokenNode) -> TokenNode {
let mut builder = TokenTreeBuilder::new();
@ -194,7 +190,7 @@ impl TokenTreeBuilder {
Box::new(move |b| {
let (start_int, end_int) = b.consume(&int.to_string());
let (start_unit, end_unit) = b.consume(unit.as_str());
let (_, end_unit) = b.consume(unit.as_str());
b.pos = end_unit;
TokenTreeBuilder::spanned_size(

View File

@ -9,7 +9,6 @@ use log::trace;
use serde::{Deserialize, Serialize};
use std::fmt;
#[allow(unused)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum NamedType {
Switch,
@ -17,7 +16,6 @@ pub enum NamedType {
Optional(SyntaxType),
}
#[allow(unused)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PositionalType {
Mandatory(String, SyntaxType),
@ -45,15 +43,6 @@ impl PositionalType {
PositionalType::Optional(name.to_string(), SyntaxType::Any)
}
#[allow(unused)]
pub(crate) fn to_coerce_hint(&self) -> Option<SyntaxType> {
match self {
PositionalType::Mandatory(_, SyntaxType::Block)
| PositionalType::Optional(_, SyntaxType::Block) => Some(SyntaxType::Block),
_ => None,
}
}
pub(crate) fn name(&self) -> &str {
match self {
PositionalType::Mandatory(s, _) => s,
@ -295,11 +284,6 @@ impl Signature {
Ok(args)
}
#[allow(unused)]
pub(crate) fn signature(&self) -> String {
format!("TODO")
}
}
pub(crate) fn evaluate_args(

View File

@ -7,22 +7,21 @@ use std::io;
pub trait Plugin {
fn config(&mut self) -> Result<Signature, ShellError>;
#[allow(unused)]
fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
fn begin_filter(&mut self, _call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
Ok(vec![])
}
#[allow(unused)]
fn filter(&mut self, input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
fn filter(&mut self, _input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
Ok(vec![])
}
#[allow(unused)]
fn end_filter(&mut self) -> Result<Vec<ReturnValue>, ShellError> {
Ok(vec![])
}
#[allow(unused)]
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {}
fn quit(&mut self){}
fn sink(&mut self, _call_info: CallInfo, _input: Vec<Tagged<Value>>) {}
fn quit(&mut self) {}
}
pub fn serve_plugin(plugin: &mut dyn Plugin) {

View File

@ -331,8 +331,7 @@ pub fn view_contents(
let cursor = cursor();
let _ = cursor.show();
#[allow(unused)]
let screen = RawScreen::disable_raw_mode();
let _ = RawScreen::disable_raw_mode();
Ok(())
}
@ -436,7 +435,6 @@ pub fn view_contents_interactive(
let cursor = cursor();
let _ = cursor.show();
#[allow(unused)]
let screen = RawScreen::disable_raw_mode();
Ok(())

View File

@ -26,8 +26,7 @@ impl TextView {
impl Plugin for TextView {
fn config(&mut self) -> Result<Signature, ShellError> {
Ok(Signature::build("textview")
.desc("Autoview of text data."))
Ok(Signature::build("textview").desc("Autoview of text data."))
}
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {
@ -200,8 +199,7 @@ fn scroll_view_lines_if_needed(draw_commands: Vec<DrawCommand>, use_color_buffer
}
let _ = cursor.show();
#[allow(unused)]
let screen = RawScreen::disable_raw_mode();
let _ = RawScreen::disable_raw_mode();
}
}

View File

@ -64,7 +64,6 @@ impl TreeView {
bold: true,
..Style::default()
};
//config.characters = UTF_CHARS_BOLD.into();
config.indent = 4;
config
};
@ -80,8 +79,7 @@ struct TreeViewer;
impl Plugin for TreeViewer {
fn config(&mut self) -> Result<Signature, ShellError> {
Ok(Signature::build("tree")
.desc("View the contents of the pipeline as a tree."))
Ok(Signature::build("tree").desc("View the contents of the pipeline as a tree."))
}
fn sink(&mut self, _call_info: CallInfo, input: Vec<Tagged<Value>>) {

View File

@ -72,9 +72,4 @@ impl NuCompleter {
Ok((replace_pos, completions))
}
// fn update(&self, line: &mut LineBuffer, start: usize, elected: &str) {
// let end = line.pos();
// line.replace(start..end, elected)
// }
}

View File

@ -501,11 +501,6 @@ impl Shell for FilesystemShell {
fn mkdir(
&self,
MkdirArgs { rest: directories }: MkdirArgs,
// RunnablePerItemContext {
// name,
// shell_manager,
// ..
// }: &RunnablePerItemContext,
name: Span,
path: &str,
) -> Result<OutputStream, ShellError> {