about summary refs log tree commit diff stats
path: root/tests/unittests/test_plugins_disco.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-05-29 17:51:33 +0200
committerMichael Vetter <jubalh@iodoru.org>2022-05-30 18:04:42 +0200
commit42fb8f86d9b3d1fd3c51a942f4d2fe17c9dc0b79 (patch)
tree4354f5adcb1e87faaf24c338dbf5ff6dfcbecf06 /tests/unittests/test_plugins_disco.c
parentd64cb38240bd6db10135b6007f42dab6851ca559 (diff)
downloadprofani-tty-42fb8f86d9b3d1fd3c51a942f4d2fe17c9dc0b79.tar.gz
Add command help for omemo qrcode
Diffstat (limited to 'tests/unittests/test_plugins_disco.c')
0 files changed, 0 insertions, 0 deletions
class='alt'>
50
51
52
53


























                                                       
                                           




















                                                                           


                                                                  
 
use std::env;
use std::fs;
use std::process;

use chrono::prelude::*;
use log;

use crate::error;
use crate::user;

lazy_static! {
    static ref VAR: String = match env::var("EDITOR") {
        Ok(ed) => {
            if &ed == "" {
                "nano".into()
            } else {
                ed
            }
        }
        Err(err) => {
            log::warn!("{:?}", err);
            "nano".into()
        }
    };
}

fn create_tmp_file<'a>() -> Result<String, &'a str> {
    let the_time = Utc::now().to_rfc3339();
    let file_name = format!("/tmp/clinte_ed_{}_{}", *user::NAME, the_time);
    match fs::write(&file_name, "") {
        Ok(_) => Ok(file_name),
        Err(err) => {
            log::warn!("{:?}", err);
            Err("Unable to create temp file")
        }
    }
}

pub fn call() -> String {
    let tmp_loc = error::helper(create_tmp_file());

    error::helper(
        process::Command::new(VAR.clone())
            .arg(tmp_loc.clone())
            .stdin(process::Stdio::inherit())
            .stdout(process::Stdio::inherit())
            .output(),
    );

    let body = error::helper(fs::read_to_string(tmp_loc.clone()));
    error::helper(fs::remove_file(tmp_loc));
    body
}