diff --git a/Cargo.lock b/Cargo.lock index f2fd779..8440cae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,46 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "anyhow" version = "1.0.70" @@ -46,12 +86,24 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "c_linked_list" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" + [[package]] name = "cc" version = "1.0.79" @@ -76,7 +128,7 @@ dependencies = [ "num-traits", "time", "wasm-bindgen", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -96,8 +148,11 @@ version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" dependencies = [ + "anstream", + "anstyle", "bitflags", "clap_lex", + "strsim", ] [[package]] @@ -128,11 +183,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cxx" @@ -196,6 +266,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "errno" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -245,6 +336,34 @@ dependencies = [ "slab", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + +[[package]] +name = "get_if_addrs" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" +dependencies = [ + "c_linked_list", + "get_if_addrs-sys", + "libc", + "winapi 0.2.8", +] + +[[package]] +name = "get_if_addrs-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" +dependencies = [ + "gcc", + "libc", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -271,6 +390,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hostname" version = "0.3.1" @@ -279,14 +404,14 @@ checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" dependencies = [ "libc", "match_cfg", - "winapi", + "winapi 0.3.9", ] [[package]] name = "iana-time-zone" -version = "0.1.54" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -327,6 +452,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "io-lifetimes" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "ipconfig" version = "0.3.1" @@ -335,7 +471,7 @@ checksum = "bd302af1b90f2463a98fa5ad469fc212c8e3175a41c3068601bfa2727591c5be" dependencies = [ "socket2", "widestring", - "winapi", + "winapi 0.3.9", "winreg", ] @@ -345,6 +481,18 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +[[package]] +name = "is-terminal" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itoa" version = "1.0.6" @@ -387,6 +535,24 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" + +[[package]] +name = "local-ip-address" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faa9d02443a1741e9f51dafdfcbffb3863b2a89c457d762b40337d6c5153ef81" +dependencies = [ + "libc", + "neli", + "thiserror", + "windows-sys 0.42.0", +] + [[package]] name = "lock_api" version = "0.4.9" @@ -436,21 +602,35 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] name = "mymy" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "chrono", "clap", + "get_if_addrs", + "hostname", + "local-ip-address", "rsntp", "serde", "serde_json", "tokio", "trust-dns-resolver", + "whoami", +] + +[[package]] +name = "neli" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508" +dependencies = [ + "byteorder", + "libc", ] [[package]] @@ -478,7 +658,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] @@ -508,7 +688,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -618,6 +798,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "rustix" +version = "0.37.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "ryu" version = "1.0.13" @@ -689,9 +883,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.109" @@ -751,7 +951,7 @@ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -783,7 +983,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -912,6 +1112,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -978,12 +1184,24 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "whoami" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c70234412ca409cc04e864e89523cb0fc37f5e1344ebed5a3ebf4192b6b9f68" + [[package]] name = "widestring" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1006,7 +1224,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1017,11 +1235,26 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.46.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -1030,7 +1263,7 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -1039,13 +1272,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -1054,47 +1302,89 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winreg" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi", + "winapi 0.3.9", ] diff --git a/Cargo.toml b/Cargo.toml index 4591f72..05c7c9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mymy" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Théo Crevon "] description = "Access the most common information about your system using a single command" @@ -17,10 +17,35 @@ path = "src/main.rs" [dependencies] anyhow = "1.0.70" -chrono = { default-features = false, version = "0.4.24" } -clap = { version = "4.2.1", features = ["std", "derive"], default-features = false } +get_if_addrs = "0.5.3" +hostname = "0.3.1" +local-ip-address = "0.5.1" rsntp = "3.0.2" -serde = { version = "1.0.159", features = ["derive"], default-features = false } serde_json = "1.0.95" -tokio = { version = "1.27.0", default-features = false, features = ["macros"] } -trust-dns-resolver = { version = "0.22.0", features = ["tokio-runtime", "system-config"], default-features = false } + +[dependencies.chrono] +version = "0.4.24" +default-features = false + +[dependencies.clap] +version = "4.2.1" +features = ["derive"] + +[dependencies.serde] +version = "1.0.159" +features = ["serde_derive"] +default-features = false + +[dependencies.tokio] +version = "1.27.0" +default-features = false +features = ["macros"] + +[dependencies.trust-dns-resolver] +version = "0.22.0" +features = ["tokio-runtime", "system-config"] +default-features = false + +[dependencies.whoami] +version = "1.4.0" +default-features = false diff --git a/README.md b/README.md index 77a20eb..ad4e798 100644 --- a/README.md +++ b/README.md @@ -2,103 +2,120 @@ [![AGPL License](https://img.shields.io/badge/license-AGPL-blue.svg)](http://www.gnu.org/licenses/agpl-3.0) -Access the most common information about your system using a single command. +mymy is a user-friendly command-line application designed to help users gather information about their system quickly, intuitively, and easily. Instead of using multiple tools to access various system details, this single tool consolidates all the important information you need. -Mymy is a command line tool that provides the most helpful information about your system in a single command. You won't need to remember which command to use or which file to consult to get the information you need. Mymy will do it for you. +## Features -We started this project because, as engineers working on three different operating systems daily, remembering which command to use or which file to open to find out about standard system information was a pain. We wanted to have a single command that would give us the information we needed without having to remember anything. +The main commands available in the mymy are: +- `ips`: Find out all the IP addresses allocated to your system, including local and external ones. +- `dns`: Discover your system's configured DNS server. +- `date`: Consult your system's configured date in a human-readable format. +- `time`: Consult your system's configured time and get the offset from the central NTP clock server. +- `datetime`: A combination of the `date` and `time` commands. +- `hostname`: Retrieve your system's hostname. +- `username`: Find out your current user's system username. +- `device-name`: Get your device's configured name. +- `os`: Identify the operating system your system is running. +- `architecture`: Determine your CPU's architecture. +- `interfaces`: List all the network interfaces configured on your system. -## Features +## Benefits -Using the `my` command, you can get the following information about your system: -- your current IP address using the `my ip` command -- your system's configured DNS servers using the `my dns` command -- your system's time, and its offset to a reference clock server using the `my time` command. -- your system's configured date using the `my date` command. -- a combination of your system's time and date using the `my datetime` command. +mymy eliminates the need to remember multiple commands and their specific syntax, as well as searching through different files for specific information. Additionally, this tool is multi-platform, making it even more convenient for users across different operating systems (MacOS, Linux, Windows). -## Installation +## Getting Started -```bash - cargo install mymy -``` - -## Usage/Examples +To use mymy, follow these steps: + +1. Install the tool by running the `cargo install mymy` command. +2. Open a terminal or command prompt. +3. Use any of the commands mentioned in the Features section, preceded by the name of the executable. + +### Example Usage + +Here are some example usages of the System Information Tool commands: ```bash -> my ip -83.173.75.136 +$ my ips +public 84.172.75.134 +local 192.168.2.246 -> my dns -8.8.8.8 +$ my dns 1.1.1.1 +8.8.8.8 192.168.1.1 -> my time -09:35:59 +02:00 -±0.0276 seconds +$ my date +Saturday, 8 April, 2023, week 14 -> my date -Monday, 03 April, 2023, week 14 +$ my time +20:51:42 UTC +02:00 +±0.0795 seconds -> my datetime -09:36:28 +02:00, Monday, 03 April, 2023, week 14 -±0.0277 seconds -``` +$ my datetime +Saturday, 8 April, 2023, week 14 +20:51:53 UTC +02:00 +±0.0801 seconds -## How to use +$ my hostname +oleiades-laptop.local -### IP address +$ my username +oleiade -To get your current IP address, use the `my ip` command. +$ my device-name +Oleiade's Laptop -```bash -> my ip -84.173.77.136 -``` - -### DNS servers +$ my os +macOS 13.2.1 -To get your system's configured DNS servers, use the `my dns` command. +$ my architecture +arm64 -```bash -> my dns -8.8.8.8 -1.1.1.1 -192.168.1.1 +$ my interfaces +lo0 127.0.0.1 +lo0 ::1 +en0 192.168.2.242 ``` -### Time +# Contributing + +We appreciate your interest in contributing to our project! This is a small, open-source Rust project, and we welcome contributions from developers of all skill levels. To ensure a smooth and enjoyable experience for everyone involved, please take a moment to read through these guidelines before getting started. -To get your system's time, and its offset to a reference clock server, use the `my time` command. +## Getting Started +1. **Fork the repository**: Start by forking the project to your own GitHub account. This will create a personal copy of the repository that you can work on. +2. **Clone the repository**: Clone your forked repository to your local machine. You can do this by running the following command: ```bash -> my time -09:35:59 +02:00 -±0.0276 seconds +git clone https://github.com/your-username/mymy.git ``` - -### Date - -To get your system's configured date, use the `my date` command. - +3. **Create a new branch**: Create a new branch for your changes. Keep the branch name descriptive and concise. For example: ```bash -> my date -Monday, 03 April, 2023, week 14 +git checkout -b feature/add-new-command ``` +4. **Make your changes**: Implement the new feature or fix the bug you've identified. Remember to follow the project's coding style and conventions. +5. **Commit your changes**: Once you've made your changes, commit them with a clear and descriptive commit message. This helps other contributors understand the purpose of your changes. +```bash +git commit -m "Add a new command for displaying system memory usage" +``` +6. **Push your changes**: Push your changes to your forked repository on GitHub. +```bash +git push origin feature/add-new-command +``` +7. **Submit a pull request**: Finally, create a pull request from your forked repository to the main project repository. Provide a clear and concise description of the changes you've made and the purpose of your pull request. -### Date and time +## Contribution Best Practices -To get a combination of your system's time and date, use the `my datetime` command. +- Always work on a new branch starting from the `develop` branch when making changes. Avoid making changes directly to the `main` branch. +- Keep your pull requests focused on a single feature or bugfix. If you have multiple unrelated changes, submit separate pull requests for each. +- Make sure your code is properly formatted and follows the project's coding style and conventions. +- Write clear and concise commit messages that describe the purpose of your changes. +- If you're fixing a bug, please provide a detailed description of the bug and steps to reproduce it. -```bash -> my datetime -09:36:28 +02:00, Monday, 03 April, 2023, week 14 -±0.0277 seconds -``` +## Reporting Bugs or Requesting Features -## Contributing +If you encounter any bugs or have a feature request, please open a new issue on the project's GitHub page. Be sure to provide a clear and concise description of the issue or feature request, and include any relevant information, such as error messages or steps to reproduce the issue. -Contributions are always welcome! +## License -See `contributing.md` for ways to get started. +This project is licensed under the AGPL-3.0 license. For more information, see the [LICENSE](LICENSE) file. diff --git a/src/datetime.rs b/src/datetime.rs new file mode 100644 index 0000000..b418b0c --- /dev/null +++ b/src/datetime.rs @@ -0,0 +1,109 @@ +use std::fmt::{Display, Formatter}; + +use anyhow::Result; +use chrono::{DateTime, Local}; +use rsntp::AsyncSntpClient; +use serde::Serialize; + +/// Returns the system date. +pub async fn date() -> Result { + let dt = Local::now(); + let now_with_tz = dt.with_timezone(&Local); + + Ok(now_with_tz.into()) +} + +#[derive(Serialize)] +pub struct Date { + day_name: String, + day_number: u8, + month_name: String, + year: i32, + week_number: u8, +} + +impl Display for Date { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.day_name)?; + write!(f, ", {} {}", self.day_number, self.month_name)?; + write!(f, ", {}", self.year)?; + write!(f, ", week {}", self.week_number) + } +} + +impl From> for Date { + fn from(dt: DateTime) -> Self { + Date { + day_name: dt.format("%A").to_string(), + day_number: dt.format("%d").to_string().parse::().unwrap(), + month_name: dt.format("%B").to_string(), + year: dt.format("%Y").to_string().parse::().unwrap(), + week_number: dt.format("%U").to_string().parse::().unwrap(), + } + } +} + +/// Returns the system time. +pub async fn time() -> Result