gr/cmds/
browse.rs

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
37
38
39
40
41
42
43
44
45
46
use std::sync::Arc;

use crate::cli::browse::BrowseOptions;
use crate::config::ConfigProperties;
use crate::remote;
use crate::remote::CacheType;
use crate::Result;

pub fn execute(
    options: BrowseOptions,
    config: Arc<dyn ConfigProperties>,
    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, None, CacheType::None)?;
            Ok(open::that(remote.get_url(BrowseOptions::MergeRequests))?)
        }
        BrowseOptions::MergeRequestId(id) => {
            let remote = remote::get_project(domain, path, config, None, CacheType::None)?;
            Ok(open::that(
                remote.get_url(BrowseOptions::MergeRequestId(id)),
            )?)
        }
        BrowseOptions::Pipelines => {
            let remote = remote::get_project(domain, path, config, None, CacheType::None)?;
            Ok(open::that(remote.get_url(BrowseOptions::Pipelines))?)
        }
        BrowseOptions::PipelineId(id) => {
            let remote = remote::get_project(domain, path, config, None, CacheType::None)?;
            Ok(open::that(remote.get_url(BrowseOptions::PipelineId(id)))?)
        }
        BrowseOptions::Releases => {
            let remote = remote::get_project(domain, path, config, None, CacheType::None)?;
            Ok(open::that(remote.get_url(BrowseOptions::Releases))?)
        }
        BrowseOptions::Manual => Ok(open::that(crate::USER_GUIDE_URL)?),
    }
}