Compare commits
39 commits
c36a17d313
...
98c9399ee4
Author | SHA1 | Date | |
---|---|---|---|
98c9399ee4 | |||
8b6f9810df | |||
cdf42417da | |||
87343f0a38 | |||
5a209ab5af | |||
fa2893bc77 | |||
4fd35736d5 | |||
66639771ac | |||
29269e2fcd | |||
d8e08459a0 | |||
6395efbeab | |||
ca8cf0cc52 | |||
ee675de202 | |||
4db6eb4317 | |||
23ffbe39dc | |||
1c3012fb32 | |||
fcf7e909ee | |||
ccbccfb11b | |||
c0dd533d81 | |||
d1001ad90d | |||
77d1236720 | |||
5bf277cf14 | |||
8f3c426359 | |||
f445a03fb2 | |||
816602fb2e | |||
24ebca3e8d | |||
48458fd1c9 | |||
746c81ab60 | |||
0615ea653c | |||
6006f92d9c | |||
7c9dca0ae2 | |||
ea2e5d6075 | |||
6ccfaedb13 | |||
e67c80a6a9 | |||
96374b6491 | |||
4788278d86 | |||
33aa131b95 | |||
e7db9c38f3 | |||
92aa3b4a3a |
11 changed files with 462 additions and 46 deletions
|
@ -94,7 +94,7 @@ Remember, be respectful.
|
|||
Entities invest their free time and motivation into making these changes,
|
||||
treat them appropiately.
|
||||
|
||||
- Since in iOwO, we mostly work based on forks, [git's remotes] work fairly good.
|
||||
- Since we mostly work based on forks, [git's remotes] work fairly good.
|
||||
- Replace things in pointy brackets (`<>`) respectively (and remove the pointy brackets).
|
||||
|
||||
## Initial steps for a new contributor or new local checkout
|
||||
|
|
223
Cargo.lock
generated
223
Cargo.lock
generated
|
@ -43,7 +43,7 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -53,7 +53,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ariadne",
|
||||
"clap",
|
||||
"dirs",
|
||||
"owo-colors",
|
||||
"ron",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ariadne"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd002a6223f12c7a95cdd4b1cb3a0149d22d37f7a9ecdb2cb691a071fe236c29"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -214,6 +238,36 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.9.0"
|
||||
|
@ -404,6 +458,12 @@ dependencies = [
|
|||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.70"
|
||||
|
@ -451,6 +511,26 @@ dependencies = [
|
|||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libredox",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.8.1"
|
||||
|
@ -489,6 +569,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
|
@ -527,6 +618,26 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiff"
|
||||
version = "0.9.0"
|
||||
|
@ -538,12 +649,38 @@ dependencies = [
|
|||
"weezl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"libc",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
|
@ -556,13 +693,37 @@ version = "0.1.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
"windows-targets 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -571,51 +732,93 @@ version = "0.52.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
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.52.0",
|
||||
"windows_aarch64_msvc 0.52.0",
|
||||
"windows_i686_gnu 0.52.0",
|
||||
"windows_i686_msvc 0.52.0",
|
||||
"windows_x86_64_gnu 0.52.0",
|
||||
"windows_x86_64_gnullvm 0.52.0",
|
||||
"windows_x86_64_msvc 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
|
|
16
crates/app/Cargo.toml
Normal file
16
crates/app/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { workspace = true, features = [ "derive", "env" ] }
|
||||
serde = { workspace = true, features = [ "derive" ] }
|
||||
ron = "0.8"
|
||||
serde_json = "1.0"
|
||||
ariadne = "0.4"
|
||||
time = { version = "0.3", features = [ "local-offset" ] }
|
||||
dirs = "5"
|
||||
owo-colors = "4"
|
93
crates/app/src/config.rs
Normal file
93
crates/app/src/config.rs
Normal file
|
@ -0,0 +1,93 @@
|
|||
use clap::Parser;
|
||||
|
||||
use self::{
|
||||
cli::Args,
|
||||
config_file::{find_config_file, Configs},
|
||||
};
|
||||
|
||||
mod cli;
|
||||
mod config_file;
|
||||
|
||||
/// this struct may hold all configuration
|
||||
pub struct Config {
|
||||
pub startup_msg: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Get the configs from all possible places (args, file, env...)
|
||||
pub fn read() -> Self {
|
||||
let args = Args::parse();
|
||||
let config_path = if let Some(config_path) = args.config_path {
|
||||
Ok(config_path)
|
||||
} else {
|
||||
find_config_file()
|
||||
};
|
||||
|
||||
// try to read a maybe existing config file
|
||||
let file_config = if let Ok(config_path) = config_path {
|
||||
let file_config = Configs::read(config_path);
|
||||
|
||||
match file_config {
|
||||
Ok(c) => Some(c),
|
||||
Err(e) => {
|
||||
eprintln!("Config error: {e:?}");
|
||||
eprintln!("Proceeding with defaults or cli args...");
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(file_config) = file_config {
|
||||
Self {
|
||||
// this is negated because to an outward api, the negative is more intuitive,
|
||||
// while in the source the other way around is more intuitive
|
||||
startup_msg: !(args.no_startup_message || file_config.no_startup_message),
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
startup_msg: !args.no_startup_message,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod error {
|
||||
/// Errors that can occur when reading configs
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
/// The config dir doesn't exist
|
||||
NoConfigDir,
|
||||
/// We didn't find a config file in the config dir
|
||||
NoConfigFileFound,
|
||||
/// An io error happened while reading/opening it!
|
||||
IoError(std::io::Error),
|
||||
/// The given extension (via an argument) isn't known.
|
||||
///
|
||||
/// Occurs if the extension is neither `.json` nor `.ron` (including if there is no extension, in which case this will be `None`).
|
||||
UnknownExtension(Option<String>),
|
||||
/// Wrapper around an `Error` from `serde_json`
|
||||
SerdeJsonError(serde_json::Error),
|
||||
/// Wrapper around a `SpannedError` from `ron`
|
||||
SerdeRonError(ron::error::SpannedError),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
fn from(value: std::io::Error) -> Self {
|
||||
Self::IoError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for ConfigError {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
Self::SerdeJsonError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ron::error::SpannedError> for ConfigError {
|
||||
fn from(value: ron::error::SpannedError) -> Self {
|
||||
Self::SerdeRonError(value)
|
||||
}
|
||||
}
|
||||
}
|
15
crates/app/src/config/cli.rs
Normal file
15
crates/app/src/config/cli.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::{builder::BoolishValueParser, ArgAction, Parser};
|
||||
|
||||
#[derive(Parser)]
|
||||
pub(crate) struct Args {
|
||||
/// Read this config file.
|
||||
#[arg(short, long)]
|
||||
pub config_path: Option<PathBuf>,
|
||||
/// Turn off the startup message.
|
||||
///
|
||||
/// The startup message is not constant and depends on the time.
|
||||
#[arg(long, env = "NO_STARTUP_MESSAGE", action = ArgAction::SetTrue, value_parser = BoolishValueParser::new())]
|
||||
pub no_startup_message: bool,
|
||||
}
|
49
crates/app/src/config/config_file.rs
Normal file
49
crates/app/src/config/config_file.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::error::ConfigError;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Configs {
|
||||
#[serde(default = "default_example_value")]
|
||||
pub example_value: i32,
|
||||
#[serde(default)]
|
||||
pub no_startup_message: bool,
|
||||
}
|
||||
|
||||
/// what the fuck serde why do i need this
|
||||
fn default_example_value() -> i32 {
|
||||
43
|
||||
}
|
||||
|
||||
/// Find the location of a config file and check if there is, in fact, a file
|
||||
pub(super) fn find_config_file() -> Result<PathBuf, ConfigError> {
|
||||
let Some(config_path) = dirs::config_dir() else {
|
||||
return Err(ConfigError::NoConfigDir);
|
||||
};
|
||||
|
||||
let ron_path = config_path.with_file_name("config.ron");
|
||||
let json_path = config_path.with_file_name("config.json");
|
||||
|
||||
if Path::new(&ron_path).exists() {
|
||||
Ok(ron_path)
|
||||
} else if Path::new(&json_path).exists() {
|
||||
Ok(json_path)
|
||||
} else {
|
||||
Err(ConfigError::NoConfigFileFound)
|
||||
}
|
||||
}
|
||||
|
||||
impl Configs {
|
||||
pub fn read(p: PathBuf) -> Result<Self, ConfigError> {
|
||||
match p.extension().map(|v| v.to_str().unwrap()) {
|
||||
Some("ron") => Ok(serde_json::from_str(&fs::read_to_string(p)?)?),
|
||||
Some("json") => Ok(ron::from_str(&fs::read_to_string(p)?)?),
|
||||
e => Err(ConfigError::UnknownExtension(e.map(|v| v.to_owned()))),
|
||||
}
|
||||
}
|
||||
}
|
42
crates/app/src/error_reporting.rs
Normal file
42
crates/app/src/error_reporting.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use std::process;
|
||||
|
||||
use ron::error::Position;
|
||||
|
||||
/// Report an `Error` from the `serde_json` crate
|
||||
pub fn report_serde_json_err(src: &str, err: serde_json::Error) -> ! {
|
||||
report_serde_err(src, err.line(), err.column(), err.to_string())
|
||||
}
|
||||
|
||||
/// Report a `SpannedError` from the `ron` crate
|
||||
pub fn report_serde_ron_err(src: &str, err: ron::error::SpannedError) -> ! {
|
||||
let Position { line, col } = err.position;
|
||||
report_serde_err(src, line, col, err.to_string())
|
||||
}
|
||||
|
||||
/// Basic function for reporting serde type of errors
|
||||
fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
|
||||
use ariadne::{Label, Report, Source};
|
||||
let offset = try_reconstruct_loc(src, line, col);
|
||||
|
||||
Report::build(ariadne::ReportKind::Error, "test", offset)
|
||||
.with_label(Label::new(("test", offset..offset)).with_message("Something went wrong here!"))
|
||||
.with_message(msg)
|
||||
.with_note("We'd like to give better errors, but serde errors are horrible to work with...")
|
||||
.finish()
|
||||
.print(("test", Source::from(src)))
|
||||
.unwrap();
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
/// Reconstruct a byte offset from the line + column numbers typical from serde crates
|
||||
fn try_reconstruct_loc(src: &str, line_nr: usize, col_nr: usize) -> usize {
|
||||
let (line_nr, col_nr) = (line_nr - 1, col_nr - 1);
|
||||
|
||||
src.lines()
|
||||
.enumerate()
|
||||
.fold(0, |acc, (i, line)| match i.cmp(&line_nr) {
|
||||
std::cmp::Ordering::Less => acc + line.len() + 1,
|
||||
std::cmp::Ordering::Equal => acc + col_nr,
|
||||
std::cmp::Ordering::Greater => acc,
|
||||
})
|
||||
}
|
17
crates/app/src/main.rs
Normal file
17
crates/app/src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use config::Config;
|
||||
use welcome_msg::print_startup_msg;
|
||||
|
||||
mod config;
|
||||
|
||||
#[allow(unused)]
|
||||
mod error_reporting;
|
||||
mod welcome_msg;
|
||||
|
||||
fn main() {
|
||||
// TODO: proper error handling
|
||||
let cfg = Config::read();
|
||||
|
||||
if cfg.startup_msg {
|
||||
print_startup_msg();
|
||||
}
|
||||
}
|
16
crates/app/src/welcome_msg.rs
Normal file
16
crates/app/src/welcome_msg.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use time::{Month, OffsetDateTime};
|
||||
|
||||
/// Print the startup message which changes depending on system time.
|
||||
pub fn print_startup_msg() {
|
||||
// now or fallback to utc
|
||||
let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
|
||||
|
||||
if now.month() == Month::June {
|
||||
// pride startup message
|
||||
println!("Hello, thanks for using iOwO and happy pride month!");
|
||||
// TODO: proper link with explaination
|
||||
println!("Why pride month is important in {}", now.year());
|
||||
} else {
|
||||
println!("Hello, thanks for using iOwO! :3");
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { workspace = true }
|
||||
executor = { path = "../executor" }
|
||||
ir = { path = "../ir" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
|
@ -1,21 +0,0 @@
|
|||
use std::{fs, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use executor::RegisteredExecutor;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {
|
||||
file: PathBuf,
|
||||
#[clap(default_value = "debug")]
|
||||
primary_executor: RegisteredExecutor,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = dbg!(Args::parse());
|
||||
|
||||
let f = fs::read_to_string(args.file)
|
||||
.expect("reading IR failed — come back to this later handle errors properly");
|
||||
let pl = ir::from_ron(&f).expect("handle me properly");
|
||||
|
||||
dbg!(pl.topological_sort());
|
||||
}
|
Loading…
Add table
Reference in a new issue