Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.122"
toml = "0.8.19"
tui-input = "0.9.0"
lazy_static = "1.5.0"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ basilk
```
All available commands are displayed inside

### Use specific data file
Run
```sh
basilk [file-name]
```
to use a specific data file in current directory. if the file does not exist, create `[file-name].[json-version].json`.

## Contributing
> [!NOTE]
> This project is now in beta version and is expected to have bugs
Expand Down
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::globals::DATA_FILE;
use std::{env, process::exit};

pub struct Cli;
Expand All @@ -12,6 +13,10 @@ impl Cli {
if arg == "--version" {
print!(env!("CARGO_PKG_VERSION"));
exit(0)
} else {
// get data file name
let mut data_file_name = DATA_FILE.lock().unwrap();
*data_file_name = Some(arg);
}
}
None => (),
Expand Down
7 changes: 7 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// global variable
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
pub static ref DATA_FILE: Mutex<Option<String>> = Mutex::new(None); // data file name(If it is none, the default file will be used)
}
13 changes: 12 additions & 1 deletion src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
use serde_json::{from_str, to_string, Value};

use crate::{
globals::DATA_FILE,
migration::{Migration, JSON_VERSIONS},
project::Project,
};
Expand All @@ -20,6 +21,12 @@ static VERSION: Mutex<String> = Mutex::new(String::new());

impl Json {
pub fn get_dir_path() -> PathBuf {
// if it is a file in a project, push the current directory
if DATA_FILE.lock().unwrap().is_some() {
let mut path = PathBuf::new();
path.push("./");
return path;
}
let mut path = dirs::config_dir().unwrap();
path.push(DIR_CONFIG_NAME);

Expand All @@ -29,7 +36,11 @@ impl Json {
fn get_json_path(version: String) -> PathBuf {
let mut path = PathBuf::new();
path.push(Json::get_dir_path().as_path());
path.push(format!("{version}.json"));
if let Some(data_file) = DATA_FILE.lock().unwrap().clone() {
path.push(format!("{data_file}.{version}.json"));
} else {
path.push(format!("{version}.json"));
}

return path;
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tui_input::{backend::crossterm::EventHandler, Input};

mod cli;
mod config;
mod globals;
mod json;
mod migration;
mod project;
Expand Down