-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts): Add helper script for finding related files
- Loading branch information
Showing
9 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
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,25 @@ | ||
#!@ZSH@ | ||
set -e | ||
|
||
cmd=$1 | ||
base=${2/.md} | ||
|
||
value() { | ||
echo $@ | ||
exit 0 | ||
} | ||
|
||
case $cmd in | ||
meta) | ||
value $base.yml | ||
;; | ||
srcid) | ||
$0 meta $2 | read meta | ||
if [[ -f $meta ]] && yq -e 'has("source")' $meta >/dev/null; then | ||
yq -r '[.source[] | select(.type == "bookid")][0].text' $meta | read bookid | ||
value $bookid | ||
fi | ||
;; | ||
esac | ||
|
||
exit 1 |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ pub mod i18n; | |
|
||
// Subcommands | ||
pub mod make; | ||
pub mod script; | ||
pub mod setup; | ||
pub mod status; | ||
|
||
|
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,37 @@ | ||
use crate::*; | ||
|
||
use std::io::prelude::*; | ||
use std::{ffi::OsString, io}; | ||
use subprocess::{Exec, Redirection}; | ||
|
||
// FTL: help-subcommand-script | ||
/// Run helper script inside CaSILE environment | ||
pub fn run(name: String, arguments: Vec<OsString>) -> Result<()> { | ||
setup::is_setup()?; | ||
show_header("script-header"); | ||
let cpus = &num_cpus::get().to_string(); | ||
let mut process = Exec::cmd(format!("{CONFIGURE_DATADIR}/scripts/{name}")).args(&arguments); | ||
let gitname = status::get_gitname()?; | ||
let git_version = status::get_git_version(); | ||
process = process | ||
.env("CASILE_CLI", "true") | ||
.env("CASILE_JOBS", cpus) | ||
.env("CASILEDIR", CONFIGURE_DATADIR) | ||
.env("CONTAINERIZED", status::is_container().to_string()) | ||
.env("LANGUAGE", locale_to_language(CONF.get_string("language")?)) | ||
.env("PROJECT", gitname) | ||
.env("PROJECTDIR", CONF.get_string("path")?) | ||
.env("PROJECTVERSION", git_version); | ||
let repo = get_repo()?; | ||
let workdir = repo.workdir().unwrap(); | ||
process = process.cwd(workdir); | ||
let process = process.stderr(Redirection::Pipe).stdout(Redirection::Pipe); | ||
let mut popen = process.popen()?; | ||
let buf = io::BufReader::new(popen.stdout.as_mut().unwrap()); | ||
for line in buf.lines() { | ||
let text: &str = | ||
&line.unwrap_or_else(|_| String::from("INVALID UTF-8 FROM CHILD PROCESS STREAM")); | ||
println!("{text}"); | ||
} | ||
Ok(()) | ||
} |