Remove dead code

This commit is contained in:
Yehuda Katz 2019-05-15 15:58:44 -07:00
parent a5a34b88a8
commit af1963d148
26 changed files with 77 additions and 231 deletions

View file

@ -8,5 +8,4 @@ crate mod select;
crate mod take; crate mod take;
crate mod to_array; crate mod to_array;
crate use command::Command;
crate use to_array::to_array; crate use to_array::to_array;

View file

@ -1,9 +1,6 @@
use crate::object::Value; use crate::object::Value;
use crate::ShellError;
use derive_new::new;
use std::cell::Cell;
use std::collections::VecDeque;
#[allow(unused)]
#[derive(Debug)] #[derive(Debug)]
pub enum LogLevel { pub enum LogLevel {
Trace, Trace,
@ -14,81 +11,9 @@ pub enum LogLevel {
Fatal, Fatal,
} }
#[allow(unused)]
#[derive(Debug)] #[derive(Debug)]
pub struct LogItem { pub struct LogItem {
level: LogLevel, level: LogLevel,
value: Value, value: Value,
} }
#[derive(Debug, Default)]
pub struct ObjectStream<T> {
queue: VecDeque<T>,
}
impl<T> ObjectStream<T> {
crate fn empty() -> ObjectStream<T> {
ObjectStream {
queue: VecDeque::new(),
}
}
crate fn iter(&self) -> impl Iterator<Item = &T> {
self.queue.iter()
}
crate fn take(&mut self) -> Option<T> {
self.queue.pop_front()
}
crate fn add(&mut self, value: T) {
self.queue.push_back(value);
}
}
#[derive(new)]
pub struct Streams {
#[new(value = "ObjectStream::empty()")]
success: ObjectStream<Value>,
#[new(value = "ObjectStream::empty()")]
errors: ObjectStream<ShellError>,
#[new(value = "ObjectStream::empty()")]
log: ObjectStream<LogItem>,
}
impl std::fmt::Debug for Streams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Streams")
}
}
impl Streams {
crate fn read(&mut self) -> Option<Value> {
self.success.take()
}
crate fn add(&mut self, value: Value) {
self.success.add(value);
}
// fn take_stream(&mut self, stream: &mut ObjectStream) -> ObjectStream {
// let mut new_stream = Cell::new(ObjectStream::default());
// new_stream.swap()
// std::mem::swap(stream, &mut new_stream);
// new_stream
// }
}
#[derive(Debug, new)]
pub struct Args {
argv: Vec<Value>,
#[new(value = "Streams::new()")]
streams: Streams,
}
impl Args {
crate fn first(&self) -> Option<&Value> {
self.argv.first()
}
}

View file

@ -1,11 +1,8 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::process::Process; use crate::object::Value;
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use derive_new::new; use derive_new::new;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct CdBlueprint; pub struct CdBlueprint;
@ -14,7 +11,7 @@ impl crate::CommandBlueprint for CdBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, args: Vec<Value>,
host: &dyn Host, _host: &dyn Host,
env: &mut Environment, env: &mut Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
let target = match args.first() { let target = match args.first() {
@ -37,7 +34,7 @@ pub struct Cd {
} }
impl crate::Command for Cd { impl crate::Command for Cd {
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> { fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
let mut stream = VecDeque::new(); let mut stream = VecDeque::new();
let path = dunce::canonicalize(self.cwd.join(&self.target).as_path())?; let path = dunce::canonicalize(self.cwd.join(&self.target).as_path())?;
stream.push_back(ReturnValue::change_cwd(path)); stream.push_back(ReturnValue::change_cwd(path));

View file

@ -1,12 +1,9 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::process::Process;
use crate::object::{dir_entry_dict, Value}; use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use crate::Command; use crate::Command;
use derive_new::new; use derive_new::new;
use std::path::PathBuf; use std::path::PathBuf;
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct LsBlueprint; pub struct LsBlueprint;
@ -14,8 +11,8 @@ pub struct LsBlueprint;
impl crate::CommandBlueprint for LsBlueprint { impl crate::CommandBlueprint for LsBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, _args: Vec<Value>,
host: &dyn crate::Host, _host: &dyn crate::Host,
env: &mut crate::Environment, env: &mut crate::Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
Ok(Box::new(Ls { Ok(Box::new(Ls {
@ -30,9 +27,9 @@ pub struct Ls {
} }
impl crate::Command for Ls { impl crate::Command for Ls {
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> { fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
let entries = let entries =
std::fs::read_dir(&self.cwd).map_err((|e| ShellError::string(format!("{:?}", e))))?; std::fs::read_dir(&self.cwd).map_err(|e| ShellError::string(format!("{:?}", e)))?;
let mut shell_entries = VecDeque::new(); let mut shell_entries = VecDeque::new();

View file

@ -4,8 +4,6 @@ use crate::object::Value;
use crate::prelude::*; use crate::prelude::*;
use crate::Command; use crate::Command;
use derive_new::new; use derive_new::new;
use std::cell::RefCell;
use std::rc::Rc;
use sysinfo::SystemExt; use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
@ -14,9 +12,9 @@ pub struct PsBlueprint;
impl crate::CommandBlueprint for PsBlueprint { impl crate::CommandBlueprint for PsBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, _args: Vec<Value>,
host: &dyn crate::Host, _host: &dyn crate::Host,
env: &mut crate::Environment, _env: &mut crate::Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
Ok(Box::new(Ps::new())) Ok(Box::new(Ps::new()))
} }
@ -26,7 +24,7 @@ impl crate::CommandBlueprint for PsBlueprint {
pub struct Ps; pub struct Ps;
impl crate::Command for Ps { impl crate::Command for Ps {
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> { fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
let mut system = sysinfo::System::new(); let mut system = sysinfo::System::new();
system.refresh_all(); system.refresh_all();

View file

@ -1,12 +1,8 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::base::reject; use crate::object::base::reject;
use crate::object::process::Process; use crate::object::Value;
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use derive_new::new; use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct RejectBlueprint; pub struct RejectBlueprint;
@ -15,8 +11,8 @@ impl crate::CommandBlueprint for RejectBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, args: Vec<Value>,
host: &dyn Host, _host: &dyn Host,
env: &mut Environment, _env: &mut Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
if args.is_empty() { if args.is_empty() {
return Err(ShellError::string("take requires an integer")); return Err(ShellError::string("take requires an integer"));

View file

@ -1,12 +1,8 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::base::select; use crate::object::base::select;
use crate::object::process::Process; use crate::object::Value;
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use derive_new::new; use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct SelectBlueprint; pub struct SelectBlueprint;
@ -15,8 +11,8 @@ impl crate::CommandBlueprint for SelectBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, args: Vec<Value>,
host: &dyn Host, _host: &dyn Host,
env: &mut Environment, _env: &mut Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
if args.is_empty() { if args.is_empty() {
return Err(ShellError::string("take requires an integer")); return Err(ShellError::string("take requires an integer"));

View file

@ -1,11 +1,7 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::process::Process; use crate::object::Value;
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use derive_new::new; use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct TakeBlueprint; pub struct TakeBlueprint;
@ -14,8 +10,8 @@ impl crate::CommandBlueprint for TakeBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, args: Vec<Value>,
host: &dyn Host, _host: &dyn Host,
env: &mut Environment, _env: &mut Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
if args.is_empty() { if args.is_empty() {
return Err(ShellError::string("take requires an integer")); return Err(ShellError::string("take requires an integer"));

View file

@ -1,11 +1,7 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::process::Process; use crate::object::Value;
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*; use crate::prelude::*;
use crate::Args;
use derive_new::new; use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)] #[derive(new)]
pub struct ToArrayBlueprint; pub struct ToArrayBlueprint;
@ -13,9 +9,9 @@ pub struct ToArrayBlueprint;
impl crate::CommandBlueprint for ToArrayBlueprint { impl crate::CommandBlueprint for ToArrayBlueprint {
fn create( fn create(
&self, &self,
args: Vec<Value>, _args: Vec<Value>,
host: &dyn Host, _host: &dyn Host,
env: &mut Environment, _env: &mut Environment,
) -> Result<Box<dyn Command>, ShellError> { ) -> Result<Box<dyn Command>, ShellError> {
Ok(Box::new(ToArray)) Ok(Box::new(ToArray))
} }

View file

@ -1,11 +1,8 @@
use crate::prelude::*; use crate::prelude::*;
use std::collections::BTreeMap;
use std::error::Error; use std::error::Error;
pub type Commands = BTreeMap<String, Box<dyn crate::CommandBlueprint>>;
pub struct Context { pub struct Context {
commands: BTreeMap<String, Box<dyn crate::CommandBlueprint>>, commands: indexmap::IndexMap<String, Box<dyn crate::CommandBlueprint>>,
crate host: Box<dyn crate::Host>, crate host: Box<dyn crate::Host>,
crate env: Environment, crate env: Environment,
} }
@ -13,7 +10,7 @@ pub struct Context {
impl Context { impl Context {
crate fn basic() -> Result<Context, Box<Error>> { crate fn basic() -> Result<Context, Box<Error>> {
Ok(Context { Ok(Context {
commands: BTreeMap::new(), commands: indexmap::IndexMap::new(),
host: Box::new(crate::env::host::BasicHost), host: Box::new(crate::env::host::BasicHost),
env: crate::Environment::basic()?, env: crate::Environment::basic()?,
}) })
@ -25,10 +22,6 @@ impl Context {
} }
} }
crate fn get_command(&mut self, name: &str) -> Option<&dyn crate::CommandBlueprint> {
self.commands.get(name).map(|c| &**c)
}
crate fn has_command(&mut self, name: &str) -> bool { crate fn has_command(&mut self, name: &str) -> bool {
self.commands.contains_key(name) self.commands.contains_key(name)
} }

View file

@ -1,4 +1,6 @@
#[allow(unused)]
use crate::prelude::*; use crate::prelude::*;
use crate::Value; use crate::Value;
use derive_new::new; use derive_new::new;

View file

@ -3,20 +3,26 @@ crate mod generic;
crate mod list; crate mod list;
crate mod table; crate mod table;
use crate::object::Value;
use crate::prelude::*; use crate::prelude::*;
use crate::Context;
use std::sync::{Arc, Mutex};
crate use entries::{EntriesListView, EntriesView}; crate use entries::{EntriesListView, EntriesView};
crate use generic::GenericView; crate use generic::GenericView;
crate use list::ListView;
crate use table::TableView; crate use table::TableView;
crate trait RenderView { crate trait RenderView {
fn render_view(&self, host: &dyn Host) -> Vec<String>; fn render_view(&self, host: &dyn Host) -> Vec<String>;
} }
crate fn print_rendered(lines: &[String], host: &mut dyn Host) { fn print_rendered(lines: &[String], host: &mut dyn Host) {
for line in lines { for line in lines {
host.stdout(line); host.stdout(line);
} }
} }
crate fn print_view(view: &impl RenderView, context: Arc<Mutex<Context>>) {
let mut ctx = context.lock().unwrap();
crate::format::print_rendered(&view.render_view(&ctx.host), &mut ctx.host);
}

View file

@ -32,7 +32,7 @@ impl EntriesView {
} }
impl RenderView for EntriesView { impl RenderView for EntriesView {
fn render_view(&self, host: &dyn Host) -> Vec<String> { fn render_view(&self, _host: &dyn Host) -> Vec<String> {
if self.entries.len() == 0 { if self.entries.len() == 0 {
return vec![]; return vec![];
} }

View file

@ -3,6 +3,7 @@ use crate::Host;
use derive_new::new; use derive_new::new;
// A list is printed one line at a time with an optional separator between groups // A list is printed one line at a time with an optional separator between groups
#[allow(unused)]
#[derive(new)] #[derive(new)]
pub struct ListView { pub struct ListView {
list: Vec<Vec<String>>, list: Vec<Vec<String>>,
@ -10,7 +11,7 @@ pub struct ListView {
} }
impl RenderView for ListView { impl RenderView for ListView {
fn render_view(&self, host: &dyn Host) -> Vec<String> { fn render_view(&self, _host: &dyn Host) -> Vec<String> {
let mut out = vec![]; let mut out = vec![];
for output in &self.list { for output in &self.list {

View file

@ -43,7 +43,7 @@ impl TableView {
} }
impl RenderView for TableView { impl RenderView for TableView {
fn render_view(&self, host: &dyn Host) -> Vec<String> { fn render_view(&self, _host: &dyn Host) -> Vec<String> {
if self.entries.len() == 0 { if self.entries.len() == 0 {
return vec![]; return vec![];
} }

View file

@ -1,6 +1,5 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![allow(unused)]
mod commands; mod commands;
mod context; mod context;
@ -11,28 +10,21 @@ mod object;
mod parser; mod parser;
mod prelude; mod prelude;
crate use crate::commands::args::{Args, Streams};
use crate::commands::command::ReturnValue; use crate::commands::command::ReturnValue;
crate use crate::commands::command::{Command, CommandAction, CommandBlueprint}; crate use crate::commands::command::{Command, CommandAction, CommandBlueprint};
use crate::context::Context; use crate::context::Context;
crate use crate::env::{Environment, Host}; crate use crate::env::{Environment, Host};
crate use crate::errors::ShellError; crate use crate::errors::ShellError;
crate use crate::format::{EntriesListView, GenericView, RenderView}; crate use crate::format::{EntriesListView, GenericView};
use crate::object::Value; use crate::object::Value;
use ansi_term::Color; use ansi_term::Color;
use conch_parser::lexer::Lexer;
use conch_parser::parse::DefaultParser;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::Editor; use rustyline::Editor;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::error::Error; use std::error::Error;
use std::rc::Rc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use subprocess::Exec; use subprocess::Exec;
use sysinfo::{self, SystemExt};
#[derive(Debug)] #[derive(Debug)]
pub enum MaybeOwned<'a, T> { pub enum MaybeOwned<'a, T> {
@ -55,7 +47,7 @@ fn main() -> Result<(), Box<Error>> {
println!("No previous history."); println!("No previous history.");
} }
let mut context = Arc::new(Mutex::new(Context::basic()?)); let context = Arc::new(Mutex::new(Context::basic()?));
{ {
use crate::commands::*; use crate::commands::*;
@ -88,8 +80,6 @@ fn main() -> Result<(), Box<Error>> {
let mut input = VecDeque::new(); let mut input = VecDeque::new();
let last = parsed.len() - 1;
for item in parsed { for item in parsed {
input = process_command( input = process_command(
crate::parser::print_items(&item), crate::parser::print_items(&item),
@ -135,17 +125,14 @@ fn process_command(
let command = &parsed[0].name(); let command = &parsed[0].name();
let arg_list = parsed[1..].iter().map(|i| i.as_value()).collect(); let arg_list = parsed[1..].iter().map(|i| i.as_value()).collect();
let streams = Streams::new();
if command == &"format" { if command == &"format" {
format(input, context); format(input, context);
Ok(VecDeque::new()) Ok(VecDeque::new())
} else if command == &"format-list" { } else if command == &"format-list" {
let view = EntriesListView::from_stream(input); let view = EntriesListView::from_stream(input);
let mut ctx = context.lock().unwrap();
crate::format::print_rendered(&view.render_view(&ctx.host), &mut ctx.host); crate::format::print_view(&view, context.clone());
Ok(VecDeque::new()) Ok(VecDeque::new())
} else { } else {
@ -155,7 +142,7 @@ fn process_command(
true => { true => {
let mut instance = ctx.create_command(command, arg_list)?; let mut instance = ctx.create_command(command, arg_list)?;
let mut result = instance.run(input)?; let result = instance.run(input)?;
let mut next = VecDeque::new(); let mut next = VecDeque::new();
for v in result { for v in result {
@ -180,12 +167,10 @@ fn process_command(
} }
fn format(input: VecDeque<Value>, context: Arc<Mutex<Context>>) { fn format(input: VecDeque<Value>, context: Arc<Mutex<Context>>) {
let mut ctx = context.lock().unwrap();
let last = input.len() - 1; let last = input.len() - 1;
for (i, item) in input.iter().enumerate() { for (i, item) in input.iter().enumerate() {
let view = GenericView::new(item); let view = GenericView::new(item);
crate::format::print_rendered(&view.render_view(&ctx.host), &mut ctx.host); crate::format::print_view(&view, context.clone());
if last != i { if last != i {
println!(""); println!("");

View file

@ -6,6 +6,5 @@ crate mod process;
crate mod types; crate mod types;
crate use base::{Primitive, Value}; crate use base::{Primitive, Value};
crate use desc::{DataDescriptor, DataDescriptorInstance};
crate use dict::Dictionary; crate use dict::Dictionary;
crate use files::dir_entry_dict; crate use files::dir_entry_dict;

View file

@ -1,16 +1,15 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::format::{EntriesView, GenericView};
use crate::object::desc::DataDescriptor; use crate::object::desc::DataDescriptor;
use ansi_term::Color; use ansi_term::Color;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use chrono_humanize::Humanize; use chrono_humanize::Humanize;
use std::fmt::Debug;
use std::time::SystemTime; use std::time::SystemTime;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Primitive { pub enum Primitive {
Nothing, Nothing,
Int(i64), Int(i64),
#[allow(unused)]
Float(f64), Float(f64),
Bytes(u128), Bytes(u128),
String(String), String(String),
@ -43,7 +42,7 @@ impl Primitive {
(true, None) => format!("Yes"), (true, None) => format!("Yes"),
(false, None) => format!("No"), (false, None) => format!("No"),
(true, Some(s)) => format!("{}", s), (true, Some(s)) => format!("{}", s),
(false, Some(s)) => format!(""), (false, Some(_)) => format!(""),
}, },
Primitive::Date(d) => format!("{}", d.humanize()), Primitive::Date(d) => format!("{}", d.humanize()),
} }
@ -59,30 +58,21 @@ pub enum Value {
} }
impl Value { impl Value {
crate fn to_shell_string(&self) -> String {
match self {
Value::Primitive(p) => p.format(None),
Value::Object(o) => format!("[object Object]"),
Value::List(l) => format!("[list List]"),
Value::Error(e) => format!("{}", e),
}
}
crate fn data_descriptors(&self) -> Vec<DataDescriptor> { crate fn data_descriptors(&self) -> Vec<DataDescriptor> {
match self { match self {
Value::Primitive(p) => vec![], Value::Primitive(_) => vec![],
Value::Object(o) => o.data_descriptors(), Value::Object(o) => o.data_descriptors(),
Value::List(l) => vec![], Value::List(_) => vec![],
Value::Error(e) => vec![], Value::Error(_) => vec![],
} }
} }
crate fn get_data(&'a self, desc: &DataDescriptor) -> crate::MaybeOwned<'a, Value> { crate fn get_data(&'a self, desc: &DataDescriptor) -> crate::MaybeOwned<'a, Value> {
match self { match self {
Value::Primitive(p) => crate::MaybeOwned::Owned(Value::nothing()), Value::Primitive(_) => crate::MaybeOwned::Owned(Value::nothing()),
Value::Object(o) => o.get_data(desc), Value::Object(o) => o.get_data(desc),
Value::List(l) => crate::MaybeOwned::Owned(Value::nothing()), Value::List(_) => crate::MaybeOwned::Owned(Value::nothing()),
Value::Error(e) => crate::MaybeOwned::Owned(Value::nothing()), Value::Error(_) => crate::MaybeOwned::Owned(Value::nothing()),
} }
} }
@ -101,8 +91,8 @@ impl Value {
crate fn format_leaf(&self, field_name: Option<&str>) -> String { crate fn format_leaf(&self, field_name: Option<&str>) -> String {
match self { match self {
Value::Primitive(p) => p.format(field_name), Value::Primitive(p) => p.format(field_name),
Value::Object(o) => format!("[object Object]"), Value::Object(_) => format!("[object Object]"),
Value::List(l) => format!("[list List]"), Value::List(_) => format!("[list List]"),
Value::Error(e) => format!("{}", e), Value::Error(e) => format!("{}", e),
} }
} }
@ -142,6 +132,7 @@ impl Value {
Value::Primitive(Primitive::Int(s.into())) Value::Primitive(Primitive::Int(s.into()))
} }
#[allow(unused)]
crate fn system_date(s: SystemTime) -> Value { crate fn system_date(s: SystemTime) -> Value {
Value::Primitive(Primitive::Date(s.into())) Value::Primitive(Primitive::Date(s.into()))
} }
@ -161,6 +152,7 @@ impl Value {
Value::Primitive(Primitive::Nothing) Value::Primitive(Primitive::Nothing)
} }
#[allow(unused)]
crate fn list(values: impl Into<Vec<Value>>) -> Value { crate fn list(values: impl Into<Vec<Value>>) -> Value {
Value::List(values.into()) Value::List(values.into())
} }

View file

@ -1,4 +1,4 @@
use crate::object::types::{AnyShell, Type}; use crate::object::types::Type;
use derive_new::new; use derive_new::new;
#[derive(new)] #[derive(new)]
@ -14,18 +14,4 @@ impl PartialEq for DataDescriptor {
} }
} }
impl DataDescriptor { impl DataDescriptor {}
crate fn any(name: impl Into<String>) -> DataDescriptor {
DataDescriptor {
name: name.into(),
readonly: true,
ty: Box::new(AnyShell),
}
}
}
#[derive(new)]
pub struct DataDescriptorInstance<'desc> {
desc: &'desc DataDescriptor,
value: crate::object::base::Value,
}

View file

@ -1,11 +1,10 @@
#[allow(unused)]
use crate::prelude::*;
use crate::object::desc::DataDescriptor; use crate::object::desc::DataDescriptor;
use crate::object::{Primitive, Value}; use crate::object::{Primitive, Value};
use crate::prelude::*;
use crate::MaybeOwned; use crate::MaybeOwned;
use derive_new::new;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Dictionary { pub struct Dictionary {
@ -30,7 +29,7 @@ impl Dictionary {
crate fn data_descriptors(&self) -> Vec<DataDescriptor> { crate fn data_descriptors(&self) -> Vec<DataDescriptor> {
self.entries self.entries
.iter() .iter()
.map(|(name, value)| { .map(|(name, _)| {
DataDescriptor::new(name.clone(), true, Box::new(crate::object::types::AnyShell)) DataDescriptor::new(name.clone(), true, Box::new(crate::object::types::AnyShell))
}) })
.collect() .collect()

View file

@ -1,11 +1,5 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::{DataDescriptor, Dictionary, Value}; use crate::object::{Dictionary, Value};
use crate::MaybeOwned;
#[derive(Debug)]
pub struct DirEntry {
dict: Dictionary,
}
#[derive(Debug)] #[derive(Debug)]
pub enum FileType { pub enum FileType {

View file

@ -1,16 +1,8 @@
use crate::object::base::{Primitive, Value}; use crate::object::base::Value;
use crate::object::desc::DataDescriptor;
use crate::object::dict::Dictionary; use crate::object::dict::Dictionary;
use crate::MaybeOwned;
use derive_new::new;
use itertools::join; use itertools::join;
use sysinfo::ProcessExt; use sysinfo::ProcessExt;
#[derive(Debug)]
pub struct Process {
dict: Dictionary,
}
crate fn process_dict(proc: &sysinfo::Process) -> Dictionary { crate fn process_dict(proc: &sysinfo::Process) -> Dictionary {
let mut dict = Dictionary::default(); let mut dict = Dictionary::default();
dict.add("name", Value::string(proc.name())); dict.add("name", Value::string(proc.name()));

View file

@ -1,4 +1,4 @@
use std::any::{Any, TypeId}; use std::any::Any;
pub trait Type { pub trait Type {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;

View file

@ -1,6 +1,7 @@
use rustyline::{completion, Context}; use rustyline::{completion, Context};
use std::collections::BTreeMap; use std::collections::BTreeMap;
#[allow(unused)]
crate struct Completer { crate struct Completer {
commands: BTreeMap<String, Box<dyn crate::CommandBlueprint>>, commands: BTreeMap<String, Box<dyn crate::CommandBlueprint>>,
} }
@ -10,9 +11,9 @@ impl completion::Completer for Completer {
fn complete( fn complete(
&self, &self,
line: &str, _line: &str,
pos: usize, _pos: usize,
ctx: &Context<'_>, _ctx: &Context<'_>,
) -> rustyline::Result<(usize, Vec<completion::Pair>)> { ) -> rustyline::Result<(usize, Vec<completion::Pair>)> {
let pairs = self let pairs = self
.commands .commands

View file

@ -5,7 +5,7 @@ use nom::character::complete::one_of;
use nom::multi::separated_list; use nom::multi::separated_list;
use nom::sequence::{preceded, terminated}; use nom::sequence::{preceded, terminated};
use nom::IResult; use nom::IResult;
use nom::{complete, named, separated_list, ws}; use nom::{complete, named, ws};
use std::str::FromStr; use std::str::FromStr;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -26,8 +26,6 @@ impl Item {
} }
crate fn print_items(items: &[Item]) -> String { crate fn print_items(items: &[Item]) -> String {
let mut out = String::new();
let formatted = items.iter().map(|item| match item { let formatted = items.iter().map(|item| match item {
Item::Bare(s) => format!("{}", s), Item::Bare(s) => format!("{}", s),
Item::Quoted(s) => format!("{:?}", s), Item::Quoted(s) => format!("{:?}", s),
@ -42,7 +40,7 @@ impl Item {
match self { match self {
Item::Quoted(s) => s, Item::Quoted(s) => s,
Item::Bare(s) => s, Item::Bare(s) => s,
Item::Int(i) => unimplemented!(), Item::Int(_) => unimplemented!(),
} }
} }
} }

View file

@ -1,7 +1,5 @@
crate use crate::commands::args::{Args, Streams}; crate use crate::commands::command::{Command, ReturnValue};
crate use crate::commands::command::{Command, CommandAction, CommandBlueprint, ReturnValue};
crate use crate::env::{Environment, Host}; crate use crate::env::{Environment, Host};
crate use crate::errors::ShellError; crate use crate::errors::ShellError;
crate use crate::format::RenderView;
crate use crate::object::{Primitive, Value}; crate use crate::object::{Primitive, Value};
crate use std::collections::VecDeque; crate use std::collections::VecDeque;