-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
print("Hello from rhai script!"); | ||
|
||
let folder = "C:\\Users\\dailyuse\\dev-src\\organize\\tests"; | ||
|
||
let apps_ext = ["exe", "msi", "apk"]; | ||
|
||
let entries = init_organize(folder); | ||
let ext_entries = filter::by_extension(entries, apps_ext); | ||
let last_modified = filter::by_last_modified(ext_entries, "..7d") | ||
|
||
action::move(last_modified, "~/backup/INBOX/@Apps/") | ||
|
||
let app_inbox_folder = "~/backup/INBOX/@Apps/"; | ||
filter::by_extension(entries, apps_ext) move_to app_inbox_folder; | ||
|
||
filter(folder->by_extension(apps_ext)) => action(move->app_inbox_folder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! `run` subcommand | ||
use std::{ | ||
fs::read_to_string, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use abscissa_core::{status_err, Application, Command, Runnable, Shutdown}; | ||
use clap::Parser; | ||
use rhai::{Engine, EvalAltResult}; | ||
|
||
use crate::{application::ORGANIZE_APP, commands::filter::FilterCmd, scripting::add}; | ||
|
||
/// Run a *.rhai script with organize | ||
#[derive(Command, Debug, Parser)] | ||
pub struct RunScriptCmd { | ||
/// Path to the *.rhai script that should be run | ||
#[clap(long)] | ||
path: PathBuf, | ||
} | ||
|
||
impl Runnable for RunScriptCmd { | ||
/// Start the application. | ||
fn run(&self) { | ||
match start_scripting_engine(&self.path) { | ||
Ok(_) => {} | ||
Err(err) => { | ||
status_err!("failed to execute script: {}", err); | ||
ORGANIZE_APP.shutdown(Shutdown::Crash) | ||
} | ||
}; | ||
} | ||
} | ||
|
||
fn start_scripting_engine(path: impl Into<PathBuf>) -> Result<(), Box<EvalAltResult>> { | ||
// Create an 'Engine' | ||
let mut engine = Engine::new(); | ||
|
||
engine.register_fn("add", add); | ||
|
||
// engine.build_type::<FilterCmd>(); | ||
|
||
// Run the script | ||
engine.run_file(path.into())?; | ||
|
||
// Done! | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ pub mod commands; | |
pub mod config; | ||
pub mod error; | ||
pub mod prelude; | ||
pub mod scripting; |
Oops, something went wrong.