Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rover): collapse profile commands into config #203

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/sputnik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Sputnik declares the `sputnik::Session` struct which is used to capture informat
```sh
body:
command:
name: config profile list
name: config list
arguments:
machine_id: edd890f0-3f8d-43f5-a22e-d3731d7e5042
session_id: a9d345b6-75f9-4bc1-9685-8475c6771610
Expand Down
4 changes: 2 additions & 2 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can provide your API key to Rover either via a [Rover command](#via-the-auth
You can provide your API key to Rover by running the following command:

```shell
rover config profile auth
rover config auth
```

This method is recommended for local development. If you have more than one API key you want to use with Rover, you can assign those keys to different [configuration profiles](#configuration-profiles).
Expand All @@ -51,7 +51,7 @@ If you don't specify a configuration profile for a command, Rover uses the defau
To view all commands for working with configuration profiles, run the following command:

```
rover config profile --help
rover config --help
```

## Logging
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ After you install Rover, you should authenticate it with [Apollo Studio](https:/
Run the following command:

```shell
rover config profile auth
rover config auth
```

This command instructs you where to obtain a personal API key and helps you set up a configuration profile. For more information, see [Configuring Rover](./configuring#configuration-profiles).
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Read the getting started guide: https://go.apollo.dev/r/start
To begin working with Rover and to authenticate with Apollo Studio,
run the following command:

$ rover config profile auth
$ rover config auth

This will prompt you for an API Key that can be generated in Apollo Studio.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ use houston as config;
use crate::command::RoverStdout;

#[derive(Debug, Serialize, StructOpt)]
/// Set a configuration profile's Apollo Studio API key
/// Authenticate a configuration profile with an API key
///
/// Running this command with the --profile flag will create a new
/// named profile that can be used across Rover with the --profile
/// flag.
/// Running this command with a --profile <name> argument will create a new
/// profile that can be referenced by name across Rover with the --profile
/// <name> argument.
///
/// Running without the --profile flag will set the api key for
/// the `default` profile.
/// Running without the --profile flag will set an API key for
/// a profile named "default".
///
/// See https://go.apollo.dev/r/api-keys for more details on Apollo's API keys.
pub struct Auth {
#[structopt(long = "profile", default_value = "default")]
#[serde(skip_serializing)]
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 20 additions & 5 deletions src/command/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod auth;
mod clear;
mod profile;
mod delete;
mod list;
mod show;

use anyhow::Result;
use serde::Serialize;
Expand All @@ -17,17 +20,29 @@ pub struct Config {

#[derive(Debug, Serialize, StructOpt)]
pub enum Command {
/// Manage configuration profiles
Profile(profile::Profile),
/// Authenticate a configuration profile with an API token
Auth(auth::Auth),

/// Clear ALL configuration
/// Clear ALL configuration profiles
Clear(clear::Clear),

/// Delete a configuration profile
Delete(delete::Delete),

/// List all configuration profiles
List(list::List),

/// View a configuration profile's details
Show(show::Show),
}

impl Config {
pub fn run(&self, config: config::Config) -> Result<RoverStdout> {
match &self.command {
Command::Profile(command) => command.run(config),
Command::Auth(command) => command.run(config),
Command::List(command) => command.run(config),
Command::Show(command) => command.run(config),
Command::Delete(command) => command.run(config),
Command::Clear(command) => command.run(config),
}
}
Expand Down
49 changes: 0 additions & 49 deletions src/command/config/profile/mod.rs

This file was deleted.

File renamed without changes.
21 changes: 7 additions & 14 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ mod tests {
#[test]
fn it_can_serialize_commands() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "profile", "list"];
let args = vec![cli_name, "config", "list"];
let rover = Rover::from_iter(args);
let actual_serialized_command = rover
.serialize_command()
.expect("could not serialize command");
let expected_serialized_command = Command {
name: "config profile list".to_string(),
name: "config list".to_string(),
arguments: HashMap::new(),
};
assert_eq!(actual_serialized_command, expected_serialized_command);
Expand All @@ -149,22 +149,15 @@ mod tests {
#[test]
fn it_can_serialize_commands_with_arguments() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![
cli_name,
"config",
"profile",
"show",
"default",
"--sensitive",
];
let args = vec![cli_name, "config", "show", "default", "--sensitive"];
let rover = Rover::from_iter(args);
let actual_serialized_command = rover
.serialize_command()
.expect("could not serialize command");
let mut expected_arguments = HashMap::new();
expected_arguments.insert("sensitive".to_string(), json!(true));
let expected_serialized_command = Command {
name: "config profile show".to_string(),
name: "config show".to_string(),
arguments: expected_arguments,
};
assert_eq!(actual_serialized_command, expected_serialized_command);
Expand All @@ -174,7 +167,7 @@ mod tests {
fn it_respects_apollo_telemetry_url() {
let apollo_telemetry_url = "https://example.com/telemetry";
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "profile", "list"];
let args = vec![cli_name, "config", "list"];
let mut rover = Rover::from_iter(args);
rover
.env_store
Expand All @@ -191,7 +184,7 @@ mod tests {
#[test]
fn it_can_be_disabled() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "profile", "list"];
let args = vec![cli_name, "config", "list"];
let mut rover = Rover::from_iter(args);
rover.env_store.insert(RoverEnvKey::TelemetryDisabled, "1");
let expect_enabled = false;
Expand All @@ -203,7 +196,7 @@ mod tests {
#[test]
fn it_is_enabled_by_default() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "profile", "list"];
let args = vec![cli_name, "config", "list"];
let rover = Rover::from_iter(args);
let expect_enabled = true;
let is_telemetry_enabled = rover.is_telemetry_enabled().unwrap();
Expand Down
8 changes: 1 addition & 7 deletions tests/config/api_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use predicates::prelude::*;
fn it_has_a_config_profile_auth_command() {
let mut cmd = Command::cargo_bin("rover").unwrap();
cmd.arg("config")
.arg("profile")
.arg("auth")
.arg("--help")
.assert()
Expand All @@ -15,11 +14,6 @@ fn it_has_a_config_profile_auth_command() {
#[test]
fn it_errors_on_an_empty_apikey() {
let mut cmd = Command::cargo_bin("rover").unwrap();
let result = cmd
.arg("config")
.arg("profile")
.arg("auth")
.write_stdin("")
.assert();
let result = cmd.arg("config").arg("auth").write_stdin("").assert();
result.stderr(predicate::str::contains("empty"));
}
2 changes: 0 additions & 2 deletions tests/config/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fn it_can_list_no_profiles() {
RoverEnvKey::ConfigHome.to_string(),
get_temp_dir().to_string_lossy().to_string(),
)
.arg("profile")
.arg("list")
.assert();
result.stderr(predicate::str::contains("No profiles"));
Expand All @@ -40,7 +39,6 @@ fn it_can_list_one_profile() {
temp_dir.to_string_lossy().to_string(),
)
.arg("config")
.arg("profile")
.arg("list")
.assert();
result.stderr(predicate::str::contains(CUSTOM_PROFILE));
Expand Down