summaryrefslogtreecommitdiff
path: root/src/cmds/comp/workspace_sheet.rs
blob: 985fe43ae759c36b5c06f76a38ff8bd6238506b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::systems::comp::context::CompletionContext;
use cli_utils::string_vec;
use just_enough_vcs::system::workspace::workspace::manager::WorkspaceManager;

pub fn comp(ctx: CompletionContext) -> Option<Vec<String>> {
    if ctx.all_words.len() > 5 {
        return None;
    }

    if (ctx.all_words.contains(&"--list-all".to_string())
        || ctx.all_words.contains(&"-A".to_string()))
        && ctx.all_words.len() > 4 {
            return None;
        }

    if ctx.current_word.starts_with('-') {
        return Some(string_vec![
            "-A",
            "--list-all",
            "-p",
            "--print-path",
            "-n",
            "--new",
            "-d",
            "--delete",
        ]);
    }

    if ctx.previous_word == "--new" || ctx.previous_word == "-n" {
        return Some(vec![]);
    }

    let rt = tokio::runtime::Runtime::new().unwrap();
    Some(rt.block_on(WorkspaceManager::new().list_sheet_names()))
}