diff --git a/src/lib/builtins/command_info.rs b/src/lib/builtins/command_info.rs index 5b09f02c045029c4adbe3d1d0c8932274d1ff6f3..cde4f7c3bb297e969430ed349c95e875a6c68859 100644 --- a/src/lib/builtins/command_info.rs +++ b/src/lib/builtins/command_info.rs @@ -9,6 +9,7 @@ use builtins_proc::builtin; use std::{borrow::Cow, env}; #[builtin( + names = "which, type", desc = "locate a program file in the current user's path", man = " SYNOPSIS @@ -42,34 +43,6 @@ pub fn which(args: &[types::Str], shell: &mut Shell<'_>) -> Status { result } -pub fn builtin_type(args: &[types::Str], shell: &mut Shell<'_>) -> Status { - // Type does not accept help flags, aka "--help". - if args.len() == 1 { - return Status::bad_argument("type: Expected at least 1 args, got only 0"); - } - - let mut result = Status::SUCCESS; - for command in &args[1..] { - match get_command_info(command, shell) { - Ok(c_type) => { - match c_type.as_ref() { - "alias" => { - if let Some(Value::Alias(alias)) = shell.variables().get(&**command) { - println!("{} is aliased to `{}`", command, &**alias); - } - } - // TODO Make it print the function. - "function" => println!("{} is a function", command), - "builtin" => println!("{} is a shell builtin", command), - _path => println!("{} is {}", command, _path), - } - } - Err(_) => result = Status::error(format!("type: {}: not found", command)), - } - } - result -} - fn get_command_info<'a>(command: &str, shell: &mut Shell<'_>) -> Result<Cow<'a, str>, ()> { match shell.variables().get(command) { Some(Value::Alias(_)) => Ok("alias".into()), diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index 285b5d568a52a3f63d50f35771fac10ea9e688fb..9639ee66f25bf6a844d976a907c1fa62a21573a1 100644 --- a/src/lib/builtins/mod.rs +++ b/src/lib/builtins/mod.rs @@ -17,7 +17,7 @@ mod test; mod variables; pub use self::{ - command_info::{builtin_type, builtin_which}, + command_info::builtin_which, conditionals::{contains, ends_with, starts_with}, echo::builtin_echo, exists::exists, @@ -181,10 +181,9 @@ impl<'a> BuiltinMap<'a> { /// Utilities concerning the filesystem /// - /// Contains `which`, `test`, `exists`, `popd`, `pushd`, `dirs`, `cd` + /// Contains `test`, `exists`, `popd`, `pushd`, `dirs`, `cd` pub fn with_files_and_directory(&mut self) -> &mut Self { - self.add("which", &builtin_which, "Shows the full path of commands") - .add("test", &builtin_test, "Performs tests on files and text") + self.add("test", &builtin_test, "Performs tests on files and text") .add("exists", &builtin_exists, "Performs tests on files and text") .add("popd", &builtin_popd, "Pop a directory from the stack") .add("pushd", &builtin_pushd, "Push a directory to the stack") @@ -225,13 +224,14 @@ impl<'a> BuiltinMap<'a> { /// Basic utilities for any ion embedded library /// - /// Contains `help`, `source`, `status`, `echo`, `type` + /// Contains `help`, `source`, `status`, `echo`, `type`, `which` pub fn with_basic(&mut self) -> &mut Self { self.add("help", &builtin_help, HELP_DESC) .add("source", &builtin_source, SOURCE_DESC) .add("status", &builtin_status, "Evaluates the current runtime status") .add("echo", &builtin_echo, "Display a line of text") - .add("type", &builtin_type, "indicates how a command would be interpreted") + .add("which", &builtin_which, "indicates what would be called for a given command") + .add("type", &builtin_which, "indicates what would be called for a given command") } /// Utilities that may be a security risk. Not included by default diff --git a/src/lib/builtins/test.rs b/src/lib/builtins/test.rs index e01bc53d3fb0634f6a6405975b66db9f15968328..230fd807ee987c8c398fdcab72153cd6411e8235 100644 --- a/src/lib/builtins/test.rs +++ b/src/lib/builtins/test.rs @@ -1,13 +1,13 @@ +use super::Status; +use crate as ion_shell; +use crate::{types, Shell}; +use builtins_proc::builtin; use std::{ fs, os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}, path::Path, time::SystemTime, }; -use crate as ion_shell; -use builtins_proc::builtin; -use super::Status; -use crate::{types, Shell}; const QUICK_GUIDE: &str = r#"Usage: test [EXPRESSION] Try 'test --help' for more information."#; @@ -219,10 +219,7 @@ fn get_modified_file_time(filename: &str) -> Option<SystemTime> { } /// Attempt to parse a &str as a usize. -fn parse_integers( - left: &str, - right: &str, -) -> Result<(Option<isize>, Option<isize>), types::Str> { +fn parse_integers(left: &str, right: &str) -> Result<(Option<isize>, Option<isize>), types::Str> { let parse_integer = |input: &str| -> Result<Option<isize>, types::Str> { match input .parse::<isize>() @@ -381,9 +378,7 @@ fn test_empty_str() { #[test] fn test_integers_arguments() { - fn vec_string(args: &[&str]) -> Vec<types::Str> { - args.iter().map(|s| (*s).into()).collect() - } + fn vec_string(args: &[&str]) -> Vec<types::Str> { args.iter().map(|s| (*s).into()).collect() } // Equal To assert_eq!(evaluate_arguments(&vec_string(&["10", "-eq", "10"])), Ok(true)); assert_eq!(evaluate_arguments(&vec_string(&["10", "-eq", "5"])), Ok(false)); diff --git a/src/lib/builtins/variables.rs b/src/lib/builtins/variables.rs index 5ebb04cd064f10177c8028c3a1afebcf83ce8a4b..16e0b2ab23ddd32192b9d8a5f4f0c873cd4a8773 100644 --- a/src/lib/builtins/variables.rs +++ b/src/lib/builtins/variables.rs @@ -123,11 +123,9 @@ pub fn drop(args: &[types::Str], shell: &mut Shell<'_>) -> Status { #[cfg(test)] mod test { use super::*; - use crate::{expansion::Expander}; + use crate::expansion::Expander; - fn vec_string(args: &[&str]) -> Vec<types::Str> { - args.iter().map(|s| (*s).into()).collect() - } + fn vec_string(args: &[&str]) -> Vec<types::Str> { args.iter().map(|s| (*s).into()).collect() } // TODO: Rewrite tests now that let is part of the grammar. // #[test]