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
36
use std::sync::Arc;

use crate::cli::browse::BrowseOptions;
use crate::config::Config;
use crate::remote;
use crate::Result;

pub fn execute(
    options: BrowseOptions,
    config: Arc<Config>,
    domain: String,
    path: String,
) -> Result<()> {
    match options {
        BrowseOptions::Repo => {
            // No need to contact the remote object, domain and path already
            // computed.
            let remote_url = format!("https://{}/{}", domain, path);
            Ok(open::that(remote_url)?)
        }
        BrowseOptions::MergeRequests => {
            let remote = remote::get_project(domain, path, config, false)?;
            Ok(open::that(remote.get_url(BrowseOptions::MergeRequests))?)
        }
        BrowseOptions::MergeRequestId(id) => {
            let remote = remote::get_project(domain, path, config, false)?;
            Ok(open::that(
                remote.get_url(BrowseOptions::MergeRequestId(id)),
            )?)
        }
        BrowseOptions::Pipelines => {
            let remote = remote::get_project(domain, path, config, false)?;
            Ok(open::that(remote.get_url(BrowseOptions::Pipelines))?)
        }
    }
}