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
//! Wrappers to manipulate [Visual Studio Code](https://code.visualstudio.com/)

use crate::{Command, CommandExt};

use std::collections::BTreeSet;



/// Parse `code --list-extensions`
///
/// # Examples
///
/// ```rust
/// # use mmrbi::vscode;
/// # if std::env::var_os("CI").is_none() {
/// assert!( vscode::list_extensions().contains("ms-vscode.cpptools"));
/// assert!(!vscode::list_extensions().contains("nonexistent"));
/// # }
/// ```
pub fn list_extensions() -> BTreeSet<String> {
    if cfg!(windows) {
        let mut cmd = Command::new("cmd");
        cmd.arg("/C").arg("call code --list-extensions");
        cmd
    } else {
        let mut cmd = Command::new("code");
        cmd.arg("--list-extensions");
        cmd
    }.stdout0().unwrap_or(String::new()).lines().map(String::from).collect::<BTreeSet<_>>()
}