commit 8f3b273337b53bd86d5594d5edc9d4ad7242bd4c Author: Yehuda Katz Date: Fri May 10 09:59:12 2019 -0700 objectshell initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..53eaa21960 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..16c27fc6ed --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,712 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "argon2rs" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "arrayvec" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "autocfg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "backtrace" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "byteorder" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cc" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "chrono" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "chrono-tz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "parse-zoneinfo 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crossbeam-deque" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "csv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "csv-core" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "derive-new" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "either" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "encode_unicode" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "failure" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "itertools" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "itoa" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "log" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "nix" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nodrop" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-integer" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num_cpus" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "objectshell" +version = "0.1.0" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono-tz 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prettytable-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustyline 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sysinfo 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "prettytable-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.54" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_users" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustyline" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ryu" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "0.15.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synstructure" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sysinfo" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "term" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "termion" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "time" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-segmentation" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" +"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" +"checksum backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f106c02a3604afcdc0df5d36cc47b44b55917dbaf3d808f71c163a0ddba64637" +"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d" +"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" +"checksum chrono-tz 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e0e430fad0384e4defc3dc6b1223d1b886087a8bf9b7080e5ae027f73851ea15" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9044e25afb0924b5a5fc5511689b0918629e85d68ea591e5e87fbf1e85ea1b3b" +"checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" +"checksum derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ca414e896ae072546f4d789f452daaecf60ddee4c9df5dc6d5936d769e3d87c" +"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" +"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" +"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" +"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" +"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" +"checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" +"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum parse-zoneinfo 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "089a398ccdcdd77b8c38909d5a1e4b67da1bc4c9dbfe6d5b536c828eddb779e5" +"checksum prettytable-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +"checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" +"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828" +"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" +"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" +"checksum rustyline 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf0a3bbb3167469f834da68a6636b93d4f6838f5438dd53ac02668abee8b997a" +"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" +"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" +"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" +"checksum sysinfo 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d88e417391431019773011a31a6c967538da388782b7711f2f6fafd9e601e55" +"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" +"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..2a5f671b78 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "objectshell" +version = "0.1.0" +authors = ["Yehuda Katz "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rustyline = "4.0.0" +sysinfo = "0.8.3" +chrono = "0.4.6" +chrono-tz = "0.5.1" +derive-new = "0.5.6" +prettytable-rs = "0.8.0" +itertools = "0.8.0" diff --git a/history.txt b/history.txt new file mode 100644 index 0000000000..3acce780b7 --- /dev/null +++ b/history.txt @@ -0,0 +1,7 @@ +hello +ps +ls +ps +ls +ps +ls diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000000..817bce375d --- /dev/null +++ b/src/commands.rs @@ -0,0 +1,3 @@ +crate mod command; +crate mod ls; +crate mod ps; diff --git a/src/commands/command.rs b/src/commands/command.rs new file mode 100644 index 0000000000..269ab367c6 --- /dev/null +++ b/src/commands/command.rs @@ -0,0 +1,10 @@ +use crate::errors::ShellError; +use crate::object::Value; + +pub trait Command { + fn run( + &mut self, + host: &dyn crate::Host, + env: &mut crate::Environment, + ) -> Result; +} diff --git a/src/commands/ls.rs b/src/commands/ls.rs new file mode 100644 index 0000000000..0d95261d42 --- /dev/null +++ b/src/commands/ls.rs @@ -0,0 +1,28 @@ +use crate::errors::ShellError; +use crate::object::process::Process; +use crate::object::{DirEntry, ShellObject, Value}; +use derive_new::new; +use sysinfo::SystemExt; + +#[derive(new)] +pub struct Ls; + +impl crate::Command for Ls { + fn run( + &mut self, + _host: &dyn crate::Host, + env: &mut crate::Environment, + ) -> Result { + let entries = + std::fs::read_dir(env.cwd()).map_err((|e| ShellError::new(format!("{:?}", e))))?; + + let mut shell_entries = vec![]; + + for entry in entries { + let value = Value::object(DirEntry::new(entry?)?); + shell_entries.push(value) + } + + Ok(Value::list(shell_entries)) + } +} diff --git a/src/commands/ps.rs b/src/commands/ps.rs new file mode 100644 index 0000000000..8e2af82740 --- /dev/null +++ b/src/commands/ps.rs @@ -0,0 +1,30 @@ +use crate::errors::ShellError; +use crate::object::process::Process; +use crate::object::{ShellObject, Value}; +use derive_new::new; +use sysinfo::SystemExt; + +#[derive(new)] +pub struct Ps { + system: sysinfo::System, +} + +impl crate::Command for Ps { + fn run( + &mut self, + _host: &dyn crate::Host, + _env: &mut crate::Environment, + ) -> Result { + self.system.refresh_all(); + + let list = self.system.get_process_list(); + + let list = list + .into_iter() + .map(|(_, process)| Value::Object(Box::new(Process::new(process.clone())))) + .take(5) + .collect(); + + Ok(Value::List(list)) + } +} diff --git a/src/env.rs b/src/env.rs new file mode 100644 index 0000000000..cc571b836e --- /dev/null +++ b/src/env.rs @@ -0,0 +1,5 @@ +crate mod environment; +crate mod host; + +crate use self::environment::Environment; +crate use self::host::Host; diff --git a/src/env/environment.rs b/src/env/environment.rs new file mode 100644 index 0000000000..2e3598edab --- /dev/null +++ b/src/env/environment.rs @@ -0,0 +1,17 @@ +use std::path::{Path, PathBuf}; + +pub struct Environment { + cwd: PathBuf, +} + +impl Environment { + pub fn basic() -> Result { + let cwd = std::env::current_dir()?; + + Ok(Environment { cwd }) + } + + pub fn cwd(&self) -> &Path { + self.cwd.as_path() + } +} diff --git a/src/env/host.rs b/src/env/host.rs new file mode 100644 index 0000000000..aea86cabf4 --- /dev/null +++ b/src/env/host.rs @@ -0,0 +1,11 @@ +pub trait Host { + fn stdout(&mut self, out: &str); +} + +crate struct BasicHost; + +impl Host for BasicHost { + fn stdout(&mut self, out: &str) { + println!("{}", out) + } +} diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000000..efe13dab22 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,22 @@ +use derive_new::new; + +#[derive(Debug, new)] +pub struct ShellError { + title: String, +} + +impl std::fmt::Display for ShellError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", &self.title) + } +} + +impl std::error::Error for ShellError {} + +impl std::convert::From for ShellError { + fn from(input: std::io::Error) -> ShellError { + ShellError { + title: format!("{}", input), + } + } +} diff --git a/src/format.rs b/src/format.rs new file mode 100644 index 0000000000..281f26a18e --- /dev/null +++ b/src/format.rs @@ -0,0 +1,16 @@ +crate mod entries; +crate mod generic; +crate mod list; +crate mod table; + +use crate::object::Value; +use crate::Host; + +crate use entries::EntriesView; +crate use generic::GenericView; +crate use list::ListView; +crate use table::TableView; + +crate trait RenderView { + fn render_view(&self, host: &dyn Host) -> Vec; +} diff --git a/src/format/entries.rs b/src/format/entries.rs new file mode 100644 index 0000000000..e48bade774 --- /dev/null +++ b/src/format/entries.rs @@ -0,0 +1,28 @@ +use crate::format::RenderView; +use crate::Host; +use derive_new::new; + +// An entries list is printed like this: +// +// name : ... +// name2 : ... +// another_name : ... +#[derive(new)] +pub struct EntriesView { + entries: Vec<(String, String)>, +} + +impl RenderView for EntriesView { + fn render_view(&self, host: &dyn Host) -> Vec { + if self.entries.len() == 0 { + return vec![]; + } + + let max_name_size: usize = self.entries.iter().map(|(n, _)| n.len()).max().unwrap(); + + self.entries + .iter() + .map(|(k, v)| format!("{:width$} : {}", k, v, width = max_name_size)) + .collect() + } +} diff --git a/src/format/generic.rs b/src/format/generic.rs new file mode 100644 index 0000000000..cf260d39e8 --- /dev/null +++ b/src/format/generic.rs @@ -0,0 +1,48 @@ +use crate::format::{RenderView, TableView}; +use crate::object::base::ToEntriesView; +use crate::object::Value; +use crate::Host; +use derive_new::new; + +// A list is printed one line at a time with an optional separator between groups +#[derive(new)] +pub struct GenericView<'value> { + value: &'value Value, +} + +impl RenderView for GenericView<'value> { + fn render_view(&self, host: &dyn Host) -> Vec { + match self.value { + Value::Primitive(p) => vec![p.format()], + Value::List(l) => { + let view = TableView::from_list(l); + + if let Some(view) = view { + view.render_view(host) + } else { + vec![] + } + // let mut list: Vec = vec![]; + // for item in l { + // match item { + // Value::Primitive(p) => list.push(p.format()), + // Value::List(l) => list.push(format!("{:?}", l)), + // Value::Object(o) => { + // let view = o.to_entries_view(); + // let out = view.render_view(host); + // list.extend(out); + // } + // } + // list.push("\n".to_string()); + // } + // list + } + + Value::Object(o) => { + let view = o.to_entries_view(); + let out = view.render_view(host); + out + } + } + } +} diff --git a/src/format/list.rs b/src/format/list.rs new file mode 100644 index 0000000000..53fe04ce85 --- /dev/null +++ b/src/format/list.rs @@ -0,0 +1,23 @@ +use crate::format::RenderView; +use crate::Host; +use derive_new::new; + +// A list is printed one line at a time with an optional separator between groups +#[derive(new)] +pub struct ListView { + list: Vec>, + sep: String, +} + +impl RenderView for ListView { + fn render_view(&self, host: &dyn Host) -> Vec { + let mut out = vec![]; + + for output in &self.list { + let string: String = output.iter().map(|l| format!("{}\n", l)).collect(); + out.push(format!("{}{}", string, self.sep)); + } + + out + } +} diff --git a/src/format/table.rs b/src/format/table.rs new file mode 100644 index 0000000000..ff4e175d24 --- /dev/null +++ b/src/format/table.rs @@ -0,0 +1,65 @@ +use crate::format::RenderView; +use crate::object::ShellObject; +use crate::object::Value; +use crate::Host; +use derive_new::new; +use prettytable::{Cell, Row, Table}; + +// An entries list is printed like this: +// +// name : ... +// name2 : ... +// another_name : ... +#[derive(new)] +pub struct TableView { + headers: Vec, + entries: Vec>, +} + +impl TableView { + pub fn from_list(values: &[Value]) -> Option { + if values.len() == 0 { + return None; + } + + let item = &values[0]; + let descs = item.data_descriptors(); + + let headers = descs.iter().map(|d| d.name.clone()).collect(); + + let mut entries = vec![]; + + for value in values { + let row = descs + .iter() + .map(|d| value.get_data(d).borrow().format_leaf()) + .collect(); + + entries.push(row); + } + + Some(TableView { headers, entries }) + } +} + +impl RenderView for TableView { + fn render_view(&self, host: &dyn Host) -> Vec { + if self.entries.len() == 0 { + return vec![]; + } + + let mut table = Table::new(); + let header: Vec = self.headers.iter().map(|h| Cell::new(h)).collect(); + + table.add_row(Row::new(header)); + + for row in &self.entries { + table.add_row(Row::new(row.iter().map(|h| Cell::new(h)).collect())); + } + + let mut out = vec![]; + table.print(&mut out).unwrap(); + + vec![String::from_utf8_lossy(&out).to_string()] + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000000..b687ed2d4e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,94 @@ +#![feature(crate_visibility_modifier)] +#![feature(in_band_lifetimes)] +#![allow(unused)] + +mod commands; +mod env; +mod errors; +mod format; +mod object; + +crate use crate::commands::command::Command; +crate use crate::env::{Environment, Host}; +crate use crate::format::RenderView; +use crate::object::base::{ToEntriesView, ToGenericView}; +use rustyline::error::ReadlineError; +use rustyline::Editor; +use std::collections::BTreeMap; +use std::error::Error; +use sysinfo::{self, SystemExt}; + +#[derive(Debug)] +pub enum MaybeOwned<'a, T> { + Owned(T), + Borrowed(&'a T), +} + +impl MaybeOwned<'a, T> { + crate fn borrow(&self) -> &T { + match self { + MaybeOwned::Owned(v) => v, + MaybeOwned::Borrowed(v) => v, + } + } +} + +fn main() -> Result<(), Box> { + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + + let mut host = crate::env::host::BasicHost; + let mut env = crate::Environment::basic()?; + + let mut commands = BTreeMap::>::new(); + + let mut system = sysinfo::System::new(); + let mut ps = crate::commands::ps::Ps::new(system); + let mut ls = crate::commands::ls::Ls; + + commands.insert("ps".to_string(), Box::new(ps)); + commands.insert("ls".to_string(), Box::new(ls)); + + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + + match commands.get_mut(&line) { + Some(command) => { + let result = command.run(&mut host, &mut env).unwrap(); + let view = result.to_generic_view(); + let rendered = view.render_view(&mut host); + + for line in rendered { + match line.as_ref() { + "\n" => println!(""), + line => println!("{}", line), + } + } + } + + _ => println!("Saw: {}", line), + } + } + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break; + } + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break; + } + Err(err) => { + println!("Error: {:?}", err); + break; + } + } + } + rl.save_history("history.txt").unwrap(); + + Ok(()) +} diff --git a/src/object.rs b/src/object.rs new file mode 100644 index 0000000000..dd56efb61c --- /dev/null +++ b/src/object.rs @@ -0,0 +1,11 @@ +crate mod base; +crate mod desc; +crate mod dict; +crate mod files; +crate mod process; +crate mod types; + +crate use base::{Primitive, ShellObject, Value}; +crate use desc::{DataDescriptor, DataDescriptorInstance}; +crate use dict::Dictionary; +crate use files::DirEntry; diff --git a/src/object/base.rs b/src/object/base.rs new file mode 100644 index 0000000000..b2d75c234a --- /dev/null +++ b/src/object/base.rs @@ -0,0 +1,134 @@ +use crate::format::{EntriesView, GenericView}; +use crate::object::desc::DataDescriptor; +use chrono::NaiveDateTime; +use std::fmt::Debug; + +#[derive(Debug)] +pub enum Primitive { + Nothing, + Int(i64), + Float(f64), + String(String), + Boolean(bool), + Date(NaiveDateTime), +} + +impl Primitive { + crate fn format(&self) -> String { + match self { + Primitive::Nothing => format!("Nothing"), + Primitive::Int(i) => format!("{}", i), + Primitive::Float(f) => format!("{}", f), + Primitive::String(s) => format!("{:?}", s), + Primitive::Boolean(b) => format!("{:?}", b), + Primitive::Date(d) => format!("{}", d), + } + } +} + +#[derive(Debug)] +pub enum Value { + Primitive(Primitive), + Object(Box), + List(Vec), +} + +impl ShellObject for Value { + fn to_shell_string(&self) -> String { + match self { + Value::Primitive(p) => p.format(), + Value::Object(o) => o.to_shell_string(), + Value::List(l) => format!("[list List]"), + } + } + fn data_descriptors(&self) -> Vec { + match self { + Value::Primitive(p) => vec![], + Value::Object(o) => o.data_descriptors(), + Value::List(l) => vec![], + } + } + + fn get_data(&'a self, desc: &DataDescriptor) -> crate::MaybeOwned<'a, Value> { + match self { + Value::Primitive(p) => crate::MaybeOwned::Owned(Value::nothing()), + Value::Object(o) => o.get_data(desc), + Value::List(l) => crate::MaybeOwned::Owned(Value::nothing()), + } + } +} + +impl Value { + crate fn format_leaf(&self) -> String { + match self { + Value::Primitive(p) => p.format(), + Value::Object(o) => format!("[object Object]"), + Value::List(l) => format!("[list List]"), + } + } + + crate fn string(s: impl Into) -> Value { + Value::Primitive(Primitive::String(s.into())) + } + + crate fn int(s: impl Into) -> Value { + Value::Primitive(Primitive::Int(s.into())) + } + + crate fn boolean(s: impl Into) -> Value { + Value::Primitive(Primitive::Boolean(s.into())) + } + + crate fn nothing() -> Value { + Value::Primitive(Primitive::Nothing) + } + + crate fn list(values: impl Into>) -> Value { + Value::List(values.into()) + } + + crate fn object(value: impl ShellObject + 'static) -> Value { + Value::Object(Box::new(value)) + } +} + +pub trait ShellObject: Debug { + fn to_shell_string(&self) -> String; + fn data_descriptors(&self) -> Vec; + fn get_data(&'a self, desc: &DataDescriptor) -> crate::MaybeOwned<'a, Value>; +} + +pub trait ToEntriesView { + fn to_entries_view(&self) -> EntriesView; +} + +impl ToEntriesView for ShellObject { + fn to_entries_view(&self) -> EntriesView { + let descs = self.data_descriptors(); + let mut entries = vec![]; + + for desc in descs { + let value = self.get_data(&desc); + + let formatted_value = match value.borrow() { + Value::Primitive(p) => p.format(), + Value::Object(o) => format!("[object Object]"), + Value::List(l) => format!("[object List]"), + }; + + entries.push((desc.name.clone(), formatted_value)) + } + + EntriesView::new(entries) + } +} + +pub trait ToGenericView { + fn to_generic_view(&self) -> GenericView; +} + +impl ToGenericView for Value { + fn to_generic_view(&self) -> GenericView<'_> { + GenericView::new(self) + } +} diff --git a/src/object/desc.rs b/src/object/desc.rs new file mode 100644 index 0000000000..d20909c10d --- /dev/null +++ b/src/object/desc.rs @@ -0,0 +1,25 @@ +use crate::object::types::{Any, Type}; +use derive_new::new; + +#[derive(new)] +pub struct DataDescriptor { + crate name: String, + crate readonly: bool, + crate ty: Box, +} + +impl DataDescriptor { + crate fn any(name: impl Into) -> DataDescriptor { + DataDescriptor { + name: name.into(), + readonly: true, + ty: Box::new(Any), + } + } +} + +#[derive(new)] +pub struct DataDescriptorInstance<'desc> { + desc: &'desc DataDescriptor, + value: crate::object::base::Value, +} diff --git a/src/object/dict.rs b/src/object/dict.rs new file mode 100644 index 0000000000..508199c6b6 --- /dev/null +++ b/src/object/dict.rs @@ -0,0 +1,73 @@ +use crate::object::desc::DataDescriptor; +use crate::object::{Primitive, Value}; +use crate::MaybeOwned; +use derive_new::new; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::rc::Rc; + +#[derive(Debug, Default)] +pub struct Dictionary { + entries: BTreeMap, +} + +impl Dictionary { + crate fn add(&mut self, name: impl Into, value: Value) { + self.entries.insert(name.into(), value); + } +} + +impl crate::object::ShellObject for Dictionary { + fn to_shell_string(&self) -> String { + format!("[object Object] lol") + } + + fn data_descriptors(&self) -> Vec { + self.entries + .iter() + .map(|(name, value)| { + DataDescriptor::new(name.clone(), true, Box::new(crate::object::types::Any)) + }) + .collect() + } + + fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> { + match self.entries.get(&desc.name) { + Some(v) => MaybeOwned::Borrowed(v), + None => MaybeOwned::Owned(Value::Primitive(Primitive::Nothing)), + } + } +} + +#[derive(Debug, Default)] +pub struct ScopedDictionary<'parent> { + entries: BTreeMap>, +} + +impl ScopedDictionary<'parent> { + crate fn add(&mut self, name: impl Into, value: impl Into>) { + self.entries.insert(name.into(), value.into()); + } +} + +impl crate::object::ShellObject for ScopedDictionary<'parent> { + fn to_shell_string(&self) -> String { + format!("[object Object] lol") + } + + fn data_descriptors(&self) -> Vec { + self.entries + .iter() + .map(|(name, value)| { + DataDescriptor::new(name.clone(), true, Box::new(crate::object::types::Any)) + }) + .collect() + } + + fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> { + match self.entries.get(&desc.name) { + Some(v) => MaybeOwned::Borrowed(v.borrow()), + None => MaybeOwned::Owned(Value::Primitive(Primitive::Nothing)), + } + } +} diff --git a/src/object/files.rs b/src/object/files.rs new file mode 100644 index 0000000000..234dca09d6 --- /dev/null +++ b/src/object/files.rs @@ -0,0 +1,57 @@ +use crate::errors::ShellError; +use crate::object::{DataDescriptor, Dictionary, ShellObject, Value}; +use crate::MaybeOwned; + +#[derive(Debug)] +pub struct DirEntry { + inner: std::fs::DirEntry, + dict: Dictionary, +} + +#[derive(Debug)] +pub enum FileType { + Dir, + File, + Symlink, +} + +impl DirEntry { + crate fn new(inner: std::fs::DirEntry) -> Result { + let mut dict = Dictionary::default(); + let filename = inner.file_name(); + dict.add("file_name", Value::string(filename.to_string_lossy())); + + let metadata = inner.metadata()?; + // let file_type = inner.file_type()?; + + let kind = if metadata.is_dir() { + FileType::Dir + } else if metadata.is_file() { + FileType::File + } else { + FileType::Symlink + }; + + dict.add("file_type", Value::string(format!("{:?}", kind))); + dict.add( + "readonly", + Value::boolean(metadata.permissions().readonly()), + ); + + Ok(DirEntry { inner, dict }) + } +} + +impl ShellObject for DirEntry { + fn to_shell_string(&self) -> String { + format!("[object DirEntry]") + } + + fn data_descriptors(&self) -> Vec { + self.dict.data_descriptors() + } + + fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> { + self.dict.get_data(desc) + } +} diff --git a/src/object/operators.rs b/src/object/operators.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/object/process.rs b/src/object/process.rs new file mode 100644 index 0000000000..9a345d37fa --- /dev/null +++ b/src/object/process.rs @@ -0,0 +1,48 @@ +use crate::object::base::{Primitive, ShellObject, Value}; +use crate::object::desc::DataDescriptor; +use crate::object::dict::Dictionary; +use crate::MaybeOwned; +use derive_new::new; +use itertools::join; +use sysinfo::ProcessExt; + +#[derive(Debug)] +pub struct Process { + inner: sysinfo::Process, + dict: Dictionary, +} + +impl Process { + crate fn new(inner: sysinfo::Process) -> Process { + let mut dict = Dictionary::default(); + dict.add("name", Value::string(inner.name())); + + let cmd = inner.cmd(); + + let cmd_value = if cmd.len() == 0 { + Value::nothing() + } else { + Value::string(join(cmd, "")) + }; + + dict.add("cmd", cmd_value); + dict.add("pid", Value::int(inner.pid() as i64)); + dict.add("status", Value::int(inner.status() as i64)); + + Process { inner, dict } + } +} + +impl ShellObject for Process { + fn to_shell_string(&self) -> String { + format!("{} - {}", self.inner.name(), self.inner.pid()) + } + + fn data_descriptors(&self) -> Vec { + self.dict.data_descriptors() + } + + fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> { + self.dict.get_data(desc) + } +} diff --git a/src/object/types.rs b/src/object/types.rs new file mode 100644 index 0000000000..7350ac6bd9 --- /dev/null +++ b/src/object/types.rs @@ -0,0 +1,5 @@ +pub trait Type {} + +pub struct Any; + +impl Type for Any {}