pub fn store_service(
    dir: &Path,
    script: &str,
    service: Option<&str>,
    service_name: Option<&str>,
) -> String {
    let rnd_name = thread_rng()
        .sample_iter(&Alphanumeric)
        .take(5)
        .map(|x| x as char)
        .collect::<String>();
    let service_name = format!("{}.toml", service_name.unwrap_or_else(|| rnd_name.as_str()));
    let script_name = format!("{}.sh", rnd_name);
    let script_path = dir.join(script_name);
    std::fs::write(&script_path, script).unwrap();
    let service = format!(
        r#"command = "/usr/bin/env bash {}"
{}"#,
        script_path.display(),
        service.unwrap_or("")
    );
    std::fs::write(dir.join(&service_name), service).unwrap();
    service_name
}
/// Creates script and service file, and stores them in dir.
/// It will append a `command` at the top of the service, with a reference to script.
/// Returns the service name.
Creates script and service file, and stores them in dir.
It will append a `command` at the top of the service, with a reference to script.
Returns the service name.
Creates script and service file and stores them in dir . It will append a ` command ` at the top of the service with a reference to script . Returns the service name .
pub fn store_service(
    dir: &Path,
    script: &str,
    service: Option<&str>,
    service_name: Option<&str>,
) -> String {
    let rnd_name = thread_rng()
        .sample_iter(&Alphanumeric)
        .take(5)
        .map(|x| x as char)
        .collect::<String>();
    let service_name = format!("{}.toml", service_name.unwrap_or_else(|| rnd_name.as_str()));
    let script_name = format!("{}.sh", rnd_name);
    let script_path = dir.join(script_name);
    std::fs::write(&script_path, script).unwrap();
    let service = format!(
        r#"command = "/usr/bin/env bash {}"
{}"#,
        script_path.display(),
        service.unwrap_or("")
    );
    std::fs::write(dir.join(&service_name), service).unwrap();
    service_name
}
pub fn store_service ( dir : & Path , script : & str , service : Option < & str > , service_name : Option < & str > , ) -> String { let rnd_name = thread_rng ( ) . sample_iter ( & Alphanumeric ) . take ( 5 ) . map ( | x | x as char ) . collect :: < String > ( ) ; let service_name = format ! ( " " service_name unwrap_or_else ( rnd_name as_str ( ) ) ) ; let script_name = format ! ( " " rnd_name ) ; let script_path = dir . join ( script_name ) ; std :: fs :: write ( & script_path , script ) . unwrap ( ) ; let service = format ! ( r#"command = "/usr/bin/env bash {}"
{}"# script_path display ( ) service unwrap_or ( " " ) ) ; std :: fs :: write ( dir . join ( & service_name ) , service ) . unwrap ( ) ; service_name }
Creates script and service file, and stores them in dir.
Creates script and service file and stores them in dir .
dir
&Path
script
&str
service
Option<&str>
service_name
Option<&str>
dir
&Path
script
&str
service
Option<&str>
service_name
Option<&str>