Skip to content

Commit 57585e9

Browse files
Add assets via include_bytes
1 parent 395222b commit 57585e9

File tree

5 files changed

+52
-58
lines changed

5 files changed

+52
-58
lines changed

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,30 @@ Before using this application, you need to install the following dependencies:
3535

3636
4. Download latest release
3737

38-
`curl -s https://api.github.com/repos/PerminovEugene/messy-folder-reorganizer-ai/releases/latest | \
38+
```sh
39+
curl -s https://api.github.com/repos/PerminovEugene/messy-folder-reorganizer-ai/releases/latest | \
3940
grep "browser_download_url.*messy-folder-reorganizer-ai-aarch64-apple-darwin.tar.gz" | \
4041
cut -d '"' -f 4 | \
41-
xargs curl -L -o messy-folder-reorganizer-ai-macos.tar.gz`
42+
xargs curl -L -o messy-folder-reorganizer-ai-macos.tar.gz
43+
```
4244

4345
5. Extract the file
4446

45-
`tar -xvzf messy-folder-reorganizer-ai-macos.tar.gz`
47+
```sh
48+
tar -xvzf messy-folder-reorganizer-ai-macos.tar.gz
49+
```
4650

47-
6. Move to /usr/local/bin for system-wide use
51+
6. Move to `/usr/local/bin` for system-wide use
4852

49-
`sudo mv messy-folder-reorganizer-ai /usr/local/bin/messy-folder-reorganizer-ai`
53+
```sh
54+
sudo mv messy-folder-reorganizer-ai /usr/local/bin/messy-folder-reorganizer-ai
55+
```
5056

5157
7. Verify installation
5258

53-
`messy-folder-reorganizer-ai --help`
59+
```sh
60+
messy-folder-reorganizer-ai --help
61+
```
5462

5563
## Usage
5664

@@ -124,6 +132,15 @@ This will create git precommit hook, which will run linters before commit.
124132
Run `cargo clippy` to reveal code problems and `cargo fmt` to fix linting errors.
125133
If you installed some dependencies - please run `cargo +nightly udeps` to check that all of them has been used.
126134

135+
## Uninstall & Purge
136+
137+
To completely remove `messy-folder-reorganizer-ai` from your system:
138+
139+
```sh
140+
rm -f /usr/local/bin/messy-folder-reorganizer-ai
141+
rm -rf ~/.messy-folder-reorganizer-ai
142+
```
143+
127144
## TODO
128145

129146
- Release.

src/ai/ai_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub async fn ask_ai_for_reordering_plan(
6363
options: &options,
6464
};
6565

66+
println!();
6667
println!("{}", "🤖 Model options:".green());
6768
println!("{}", serde_json::to_string_pretty(&options).unwrap());
6869

src/configuration/embedded_assets.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Embedded assets (compile-time constants).
2+
/// Adjust the relative paths so they point correctly to your files on disk.
3+
/// For example, if this file is at `src/configuration/mod.rs`,
4+
/// and your `assets` folder is at the project root, you might need `../../assets/...`.
5+
pub const CONFIG_FILE_BYTES: &[u8] = include_bytes!("../../assets/config.toml");
6+
pub const INITIAL_PROMPT_FILE_BYTES: &[u8] =
7+
include_bytes!("../../assets/prompts/initial_sort_request.md");

src/configuration/init.rs

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,86 +5,54 @@ use std::path::{Path, PathBuf};
55
use crate::configuration::consts::{
66
CONFIGURATION_FILE, CONFIGURATION_FOLDER, INITIAL_PROMPT_FILE, PROMPTS_FOLDER,
77
};
8+
// Make sure you can access the embedded constants (either inline or in another mod)
9+
use crate::configuration::embedded_assets::{CONFIG_FILE_BYTES, INITIAL_PROMPT_FILE_BYTES};
810

911
pub fn init() {
10-
let assets = get_runtime_assets_dir();
11-
let in_project_config_path = assets.join(CONFIGURATION_FILE);
12-
let in_project_initial_prompt_path = assets.join(PROMPTS_FOLDER).join(INITIAL_PROMPT_FILE);
13-
1412
create_application_config_folder();
1513

16-
let config_file_path = get_config_file_path();
17-
create_application_config_file(&config_file_path, in_project_config_path);
14+
let config_file_path = get_config_file_path(); // e.g. ~/.messy-folder-reorganizer-ai/config.toml
15+
let initial_prompt_file_path = get_initial_prompt_file_path(); // e.g. ~/.messy-folder-reorganizer-ai/prompts/initial_prompt.txt
1816

19-
let initial_prompt_file_path = get_initial_prompt_file_path();
20-
create_application_config_file(&initial_prompt_file_path, in_project_initial_prompt_path);
17+
create_application_file_if_missing(&config_file_path, CONFIG_FILE_BYTES);
18+
create_application_file_if_missing(&initial_prompt_file_path, INITIAL_PROMPT_FILE_BYTES);
2119
}
2220

23-
/// Returns the correct path to the `assets/` directory for both `cargo run` and installed versions.
24-
fn get_runtime_assets_dir() -> PathBuf {
25-
let exe_path = env::current_exe().unwrap_or_else(|_| PathBuf::from("."));
26-
27-
// If running from Cargo (`target/debug/` or `target/release/`), go up twice to find `src/`
28-
if exe_path.to_string_lossy().contains("target/") {
29-
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); // Root of the project
30-
return manifest_dir.join("assets");
21+
fn create_application_config_folder() {
22+
let home_dir = env::var("HOME").unwrap_or_else(|_| ".".to_string());
23+
let config_dir = format!("{}/.messy-folder-reorganizer-ai", home_dir);
24+
if !Path::new(&config_dir).exists() {
25+
fs::create_dir_all(&config_dir).expect("Failed to create config directory");
3126
}
3227

33-
// Otherwise, assume assets are in the same folder as the installed binary
34-
exe_path
35-
.parent()
36-
.map(|dir| dir.join("assets"))
37-
.unwrap_or_else(|| PathBuf::from("assets"))
28+
let prompts_dir = format!("{}/.messy-folder-reorganizer-ai/prompts", home_dir);
29+
if !Path::new(&prompts_dir).exists() {
30+
fs::create_dir_all(&prompts_dir).expect("Failed to create prompts directory");
31+
}
3832
}
3933

4034
pub fn get_config_file_path() -> PathBuf {
41-
let home_dir: String = env::var("HOME").unwrap_or_else(|_| ".".to_string());
35+
let home_dir = env::var("HOME").unwrap_or_else(|_| ".".to_string());
4236
Path::new(&home_dir)
4337
.join(CONFIGURATION_FOLDER)
4438
.join(CONFIGURATION_FILE)
4539
}
4640

4741
pub fn get_initial_prompt_file_path() -> PathBuf {
48-
let home_dir: String = env::var("HOME").unwrap_or_else(|_| ".".to_string());
42+
let home_dir = env::var("HOME").unwrap_or_else(|_| ".".to_string());
4943
Path::new(&home_dir)
5044
.join(CONFIGURATION_FOLDER)
5145
.join(PROMPTS_FOLDER)
5246
.join(INITIAL_PROMPT_FILE)
5347
}
5448

55-
fn create_application_config_folder() {
56-
let home_dir = env::var("HOME").unwrap_or_else(|_| ".".to_string());
57-
let config_dir = format!("{}/.messy-folder-reorganizer-ai", home_dir);
58-
if !Path::new(&config_dir).exists() {
59-
fs::create_dir_all(&config_dir).expect("Failed to create config directory");
60-
}
61-
62-
let prompts_dir = format!("{}/.messy-folder-reorganizer-ai/prompts", home_dir);
63-
if !Path::new(&prompts_dir).exists() {
64-
fs::create_dir_all(&prompts_dir).expect("Failed to create prompts directory");
65-
}
66-
}
67-
68-
fn create_application_config_file(config_file_path: &Path, source: PathBuf) {
49+
fn create_application_file_if_missing(config_file_path: &Path, embedded_content: &[u8]) {
6950
if !config_file_path.exists() {
70-
// Ensure parent directory exists
7151
if let Some(parent) = config_file_path.parent() {
7252
fs::create_dir_all(parent).expect("Failed to create parent directories");
7353
}
7454

75-
// Copy the file
76-
println!("Copying from source: {:?}", source);
77-
println!("Copying to: {:?}", config_file_path);
78-
79-
match fs::read(&source) {
80-
Ok(content) => {
81-
fs::write(config_file_path, content).expect("Failed to copy config file");
82-
println!("Initialized {:?} file.", config_file_path);
83-
}
84-
Err(e) => {
85-
println!("Warning: Could not read source file {:?} ({})", source, e);
86-
panic!("File one not found");
87-
}
88-
}
55+
fs::write(config_file_path, embedded_content).expect("Failed to write embedded content");
56+
println!("Initialized file: {:?}", config_file_path);
8957
}
9058
}

src/configuration/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod args;
22
pub mod config;
33
pub mod consts;
4+
pub mod embedded_assets;
45
pub mod init;
56
pub mod read_config;

0 commit comments

Comments
 (0)