-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds
rover docs open
and rover docs list
- Loading branch information
1 parent
a8c8195
commit b6cb4e9
Showing
9 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::{command::RoverStdout, Result}; | ||
|
||
use super::shortlinks; | ||
|
||
use serde::Serialize; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, Serialize, StructOpt)] | ||
pub struct List {} | ||
|
||
impl List { | ||
pub fn run(&self) -> Result<RoverStdout> { | ||
Ok(RoverStdout::DocsList( | ||
shortlinks::get_shortlinks_with_description(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
mod list; | ||
mod open; | ||
pub mod shortlinks; | ||
|
||
use serde::Serialize; | ||
use structopt::StructOpt; | ||
|
||
use crate::{command::RoverStdout, Result}; | ||
|
||
#[derive(Debug, Serialize, StructOpt)] | ||
pub struct Docs { | ||
#[structopt(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Serialize, StructOpt)] | ||
pub enum Command { | ||
/// List all available docs links | ||
List(list::List), | ||
|
||
/// Open a docs link | ||
Open(open::Open), | ||
} | ||
|
||
impl Docs { | ||
pub fn run(&self) -> Result<RoverStdout> { | ||
match &self.command { | ||
Command::List(command) => command.run(), | ||
Command::Open(command) => command.run(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::{command::RoverStdout, Result}; | ||
|
||
use super::shortlinks; | ||
|
||
use serde::Serialize; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, Serialize, StructOpt)] | ||
pub struct Open { | ||
#[structopt(name = "slug", possible_values = &shortlinks::possible_shortlinks())] | ||
shortlink: String, | ||
} | ||
|
||
impl Open { | ||
pub fn run(&self) -> Result<RoverStdout> { | ||
let url = format!("https://go.apollo.dev/r/{}", &self.shortlink); | ||
webbrowser::open(&url)?; | ||
Ok(RoverStdout::None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashMap; | ||
|
||
pub fn get_shortlinks_with_description() -> HashMap<&'static str, &'static str> { | ||
let mut links = HashMap::new(); | ||
links.insert("docs", "Rover's Documentation Homepage"); | ||
links.insert("api-keys", "Understanding Apollo's API Keys"); | ||
links.insert("contributing", "Contributing to Rover"); | ||
links.insert("start", "Getting Started with Rover"); | ||
links | ||
} | ||
|
||
pub fn possible_shortlinks() -> Vec<&'static str> { | ||
let mut res = Vec::new(); | ||
for (slug, _) in get_shortlinks_with_description() { | ||
res.push(slug); | ||
} | ||
res | ||
} | ||
|
||
mod tests { | ||
#[test] | ||
fn can_make_shortlink_vec_from_map() { | ||
let shortlinks = super::possible_shortlinks(); | ||
assert!(!shortlinks.is_empty()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters