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

chore(cli): change name of --output option to --format #1413

Merged
merged 31 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
894d81a
feat(cli): change --output option name to --format
gocamille Oct 21, 2022
bda3c89
Merge branch 'main' into camille/update-format-option (#1403)
EverlastingBugstopper Nov 10, 2022
f587f38
feat(cli): Include logic to deprecate output option
gocamille Nov 24, 2022
7b75c1c
feat(cli): refactor rover_output logic
gocamille Nov 25, 2022
e08c20c
feat(cli): add a print function to stdout plain text
gocamille Nov 26, 2022
e8eb42c
feat(cli): add matching and error handling for plaintext stdout
gocamille Nov 26, 2022
0a7dd7c
feat(cli): Add deprecation message for '--output'
gocamille Nov 27, 2022
0520dab
feat(cli): remove unused imports
gocamille Nov 27, 2022
49fd6b9
feat(cli): update '--output' deprecation msg from error to warning
gocamille Nov 28, 2022
7ff032b
feat(cli): Update changelog
gocamille Nov 28, 2022
e72f260
feat(cli): add indent to changelog
gocamille Nov 28, 2022
c6c90f4
feat(cli): refactor from clippy suggestions
gocamille Nov 30, 2022
fe9abf2
feat(cli): remove unused module
gocamille Nov 30, 2022
3c6c21d
feat(cli): Add print to file option for output
gocamille Dec 1, 2022
13d2c24
feat(cli): update changelog
gocamille Dec 1, 2022
ee07e6e
feat(cli): Add logic to deprecate --output and print to file
gocamille Jan 9, 2023
a0f4dd6
feat(cli): Add emoji to file output message
gocamille Jan 10, 2023
d39d937
feat(cli): remove unneeded comments and imports
gocamille Jan 10, 2023
d05f808
feat(cli): rename RoverOutputTrait
gocamille Jan 10, 2023
f099b32
feat(cli): update output documentation to include --output deprecation
gocamille Jan 10, 2023
ca45449
feat(cli): re-include SdlType crate
gocamille Jan 10, 2023
1c8611e
feat(cli): change doc references from to
gocamille Jan 10, 2023
d66b79a
Edits to new docs around --format
Jan 10, 2023
b602a41
Edits to new docs around --format (#1469)
gocamille Jan 11, 2023
2762f1c
Merge branch 'main' into camille/update-format-option
EverlastingBugstopper Jan 18, 2023
b378556
chore: lints and version update in docs
EverlastingBugstopper Jan 18, 2023
dea54ba
Merge branch 'main' into camille/update-format-option
EverlastingBugstopper Jan 18, 2023
28dd777
Merge branch 'main' into camille/update-format-option
EverlastingBugstopper Jan 18, 2023
d9d2ceb
Merge branch 'main' into camille/update-format-option
EverlastingBugstopper Jan 19, 2023
4482f83
fix: make --watch work with new --output (#1478)
EverlastingBugstopper Jan 19, 2023
ce3f80c
chore: small changes on warning text
EverlastingBugstopper Jan 19, 2023
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## 📚 Documentation -->

# [0.10.1] - 2022-11-28

## 🚀 Features

- **Replace the '--output' option type with '--format' - @gocamille, #1413 fixes #1212**

This change adds the new option, `--format`, to allow users to define the format type for messages printed to `stdout` (either by passing `plain` or `json` as an argument to `--format`). This replaces the use of `--output` for defining format types. The `--output` option will be available to define the output file type instead, following [Command Line Interface Guidelines for file outputs](https://clig.dev/#:~:text=%2Do%2C%20%2D%2Doutput%3A%20Output%20file.%20For%20example%2C%20sort%2C%20gcc.). This is an additive, non-breaking change and using the `--output` option will continue to be valid.


# [0.10.0] - 2022-11-10

> Important: 1 potentially breaking change below, indicated by **❗ BREAKING ❗**
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ Options:
-l, --log <LOG_LEVEL>
Specify Rover's log level

--format <FORMAT_TYPE>
Specify Rover's format type

[default: plain]
[possible values: plain, json]

--output <OUTPUT_TYPE>
Specify Rover's output type

[default: plain]
[possible values: plain, json]
[possible values: plain, json, filename]

--insecure-accept-invalid-certs
Accept invalid certificates when performing HTTPS requests.
Expand Down
2 changes: 2 additions & 0 deletions crates/rover-std/src/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Emoji {
Skull,
Compose,
Warn,
Memo,
}

impl Emoji {
Expand All @@ -42,6 +43,7 @@ impl Emoji {
Skull => "💀 ",
Compose => "🎶 ",
Warn => "⚠️ ",
Memo => "📝 ",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/commands/graphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You can also save the output to a local `.graphql` file like so:

```bash
# Creates prod-schema.graphql or overwrites if it already exists
rover graph fetch my-graph@my-variant > prod-schema.graphql
rover graph fetch my-graph@my-variant --output prod-schema.graphql
```

> For more on passing values via `stdout`, see [Conventions](../conventions#using-stdout).
Expand Down
6 changes: 3 additions & 3 deletions docs/source/commands/readmes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ By default, the README is output to `stdout`. You can also save the output to a

```bash
# Creates README.md or overwrites if it already exists
rover readme fetch my-graph@my-variant > README.md
rover readme fetch my-graph@my-variant --output README.md
```

You can also request the output as JSON with the `--output json` option:
You can also request the output as JSON with the `--format json` option:

```bash
rover readme fetch my-graph@my-variant --output json
rover readme fetch my-graph@my-variant --format json
```

> For more on passing values via `stdout`, see [Conventions](../conventions#using-stdout).
Expand Down
4 changes: 2 additions & 2 deletions docs/source/commands/subgraphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The subgraph must be reachable by Rover. The subgraph does _not_ need to have in

#### Watching for schema changes

If you pass `--watch` to `rover subgraph introspect`, Rover introspects your subgraph every second. Whenever the returned schema differs from the _previously_ returned schema, Rover outputs the updated schema.
If you pass `--watch` to `rover subgraph introspect`, Rover introspects your subgraph every second. Whenever the returned schema differs from the _previously_ returned schema, Rover outputs the updated schema. This is most useful when combined with the `--output <OUTPUT_FILE>` argument which will write the introspection response out to a file whenever its contents change.

#### Including headers

Expand Down Expand Up @@ -83,7 +83,7 @@ You can also save the output to a local `.graphql` file like so:

```bash
# Creates accounts-schema.graphql or overwrites if it already exists
rover subgraph introspect http://localhost:4000 > accounts-schema.graphql
rover subgraph introspect http://localhost:4000 --output accounts-schema.graphql
```

> For more on passing values via `stdout`, see [Using `stdout`](../conventions#using-stdout).
Expand Down
2 changes: 1 addition & 1 deletion docs/source/commands/supergraphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ You can save the schema output to a local `.graphql` file like so:

```bash
# Creates prod-schema.graphql or overwrites if it already exists
rover supergraph compose --config ./supergraph.yaml > prod-schema.graphql
rover supergraph compose --config ./supergraph.yaml --output prod-schema.graphql
```

> For more on passing values via `stdout`, see [Using `stdout`](../conventions#using-stdout).
Expand Down
35 changes: 28 additions & 7 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,24 @@ rover graph check my-graph@prod --schema ./schema.graphql --log debug
If Rover log messages are unhelpful or unclear, please leave us feedback in an
[issue on GitHub](https://github.com/apollographql/rover/issues/new/choose)!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @StephenBarlow -- let us know if this copy needs to be refined!

## Output format

### `--output plain` (default)
## Configuring output

By default, Rover prints the main output of its commands to `stdout` in plaintext. It also prints a _descriptor_ for that output to `stderr` if it thinks it's being operated by a human (it checks whether the terminal is TTY).

> For more on `stdout`, see [Conventions](./conventions/#using-stdout).
> For more on `stdout`, see [Conventions](https://chat.openai.com/conventions/#using-stdout).

Every Rover command supports two options for configuring its output behavior:

- `--format`, for [setting the output format](#setting-output-format) (`plain` or `json`)
- `--output`, for [writing a command's output to a file](#setting-output-location) instead of `stdout`

### `--output json`
### JSON output

For more programmatic control over Rover's output, you can pass `--output json` to any command. Rover JSON output has the following minimal structure:
> **Note:** The `--format` option was added in Rover v0.11.0. Earlier versions of Rover use the `--output` option to set output format.
>
> Current versions of Rover still support using `--output` this way, but that support is deprecated and will be removed in a future release.

For more programmatic control over Rover's output, you can pass `--format json` to any command. Rover JSON output has the following minimal structure:

```json title="success_example"
{
Expand Down Expand Up @@ -232,7 +239,21 @@ This particular `error` object includes `details` about what went wrong. Notice

#### Example `jq` script

You can combine the `--output json` flag with the [`jq`](https://stedolan.github.io/jq/) command line tool to create powerful custom workflows. For example, [this gist](https://gist.github.com/EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a) demonstrates converting output from `rover {sub}graph check my-graph --output json` to Markdown.
You can combine the `--format json` flag with the [`jq`](https://stedolan.github.io/jq/) command line tool to create powerful custom workflows. For example, [this gist](https://gist.github.com/EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a) demonstrates converting output from `rover {sub}graph check my-graph --format json` to Markdown.

### Writing to a file

The `--output` option enables you to specify a file destination for writing a Rover command's output:

```bash
rover supergraph compose --output ./supergraph-schema.graphql --config ./supergraph.yaml
```

If the specified file already exists, Rover overwrites it.

> **Note:** This functionality is available in Rover v0.11.0 and later. In _earlier_ versions of Rover, the `--output` option instead provides the functionality that's now provided by the [`--format` option](#json-output).
>
> Current versions of Rover still support using `--output` like `--format`, but that support is deprecated and will be removed in a future release.

## Setting config storage location

Expand Down
12 changes: 5 additions & 7 deletions docs/source/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ All Rover commands that interact with the Apollo graph registry require a graph

### Using `stdout`

Rover commands print to `stdout` in a predictable, portable format. This enables output to be used elsewhere (such as in another CLI, or as input to another Rover command). To help maintain this predictability, Rover prints logs to `stderr` instead of `stdout`.
Rover commands print to `stdout` in a predictable, portable format. This enables output to be used elsewhere (such as in another CLI, or as input to another Rover command). To help maintain this predictability, Rover prints progress logs to `stderr` instead of `stdout`.

To redirect Rover's output to a location other than your terminal, you can use the pipe `|` or output redirect `>` operators.
To redirect Rover's output to a location other than your terminal, you can use the `--output <OUTPUT_FILE>` argument, the pipe `|` operator, or the redirect `>` operator.

#### Pipe `|`

Expand All @@ -53,12 +53,12 @@ rover graph introspect http://localhost:4000 | pbcopy

In this example, the output of the `introspect` command is piped to `pbcopy`, a MacOS command that copies a value to the clipboard. Certain Rover commands also accept values from `stdin`, as explained in [Using `stdin`](#using-stdin).

#### Output redirect `>`
#### Output to a file

Use the output redirect operator to write the `stdout` of a command to a file, like so:
Use the `--output <OUTPUT_FILE>` argument to write command output to a file.

```
rover graph fetch my-graph@prod > schema.graphql
rover graph fetch my-graph@prod --output schema.graphql
```

In this example, the schema returned by `graph fetch` is written to the file `schema.graphql`. If this file already exists, it's overwritten. Otherwise, it's created.
Expand All @@ -72,5 +72,3 @@ rover graph introspect http://localhost:4000 | rover graph check my-graph --sche
```

In this example, the schema returned by `graph introspect` is then passed as the `--schema` option to `graph check`.

> Currently, `--schema` is the only Rover option that accepts a file path.
14 changes: 6 additions & 8 deletions docs/source/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ As a workaround, you might be able to use `cat` to combine multiple files and pa

### Machine-readable output

In the Apollo CLI, many commands support alternate output formatting options, such as `--json` and `--markdown`. Currently, Rover only supports `--output json`, and leaves markdown formatting up to the consumer. For more information on JSON output in Rover, see [these docs](./configuring/#--output-json).
In the Apollo CLI, many commands support alternate output formatting options, such as `--json` and `--markdown`. Currently, Rover only supports `--format json`, and leaves markdown formatting up to the consumer. For more information on JSON output in Rover, see [these docs](./configuring/#json-output).

An example script for converting output from `rover {sub}graph check my-graph --output json` can be found in [this gist](https://gist.github.com/EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a).
An example script for converting output from `rover {sub}graph check my-graph --format json` can be found in [this gist](https://gist.github.com/EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a).

## Examples

Expand All @@ -160,8 +160,8 @@ An example script for converting output from `rover {sub}graph check my-graph --
apollo client:download-schema --graph my-graph --variant prod

## Rover ##
# automatically outputs to stdout. Can redirect to schema.graphql
rover graph fetch my-graph@prod > schema.graphql
# automatically outputs to stdout. Can redirect to schema.graphql with the `--output <OUTPUT_FILE>` argument
rover graph fetch my-graph@prod --output schema.graphql
```

### Fetching a graph's schema from introspection
Expand All @@ -173,9 +173,9 @@ rover graph fetch my-graph@prod > schema.graphql
apollo service:download --endpoint http://localhost:4000

## Rover ##
# automatically outputs to stdout. Can redirect to schema.graphql
# automatically outputs to stdout. Can redirect to schema.graphql with the `--output <OUTPUT_FILE>` argument
# can ONLY output SDL
rover graph introspect http://localhost:4000
rover graph introspect http://localhost:4000 --output schema.graphql
```

### Publishing a monolithic schema to the Apollo graph registry
Expand Down Expand Up @@ -261,8 +261,6 @@ rover graph introspect http://localhost:4001 --header "authorization: Bearer wxy
| rover graph check my-graph@prod --schema -
```



### Pushing Subgraph Changes (with a config file)

```js
Expand Down
4 changes: 2 additions & 2 deletions src/bin/rover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use robot_panic::setup_panic;
use rover::cli::Rover;

#[calm_io::pipefail]
fn main() -> std::io::Result<()> {
fn main() -> Result<_, std::io::Error> {
setup_panic!(Metadata {
name: rover::PKG_NAME.into(),
version: rover::PKG_VERSION.into(),
authors: rover::PKG_AUTHORS.into(),
homepage: rover::PKG_HOMEPAGE.into(),
repository: rover::PKG_REPOSITORY.into()
});
Rover::run_from_args()
Ok(Rover::run_from_args())
}
47 changes: 21 additions & 26 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use lazycell::{AtomicLazyCell, LazyCell};
use reqwest::blocking::Client;
use serde::Serialize;

use crate::command::output::JsonOutput;
use crate::command::{self, RoverOutput};
use crate::options::OutputOpts;
use crate::utils::{
client::{ClientBuilder, ClientTimeout, StudioClientConfig},
env::{RoverEnv, RoverEnvKey},
Expand Down Expand Up @@ -61,9 +61,8 @@ pub struct Rover {
#[serde(serialize_with = "option_from_display")]
log_level: Option<Level>,

/// Specify Rover's output type
#[arg(long = "output", default_value = "plain", global = true)]
output_type: OutputType,
#[clap(flatten)]
output_opts: OutputOpts,

/// Accept invalid certificates when performing HTTPS requests.
///
Expand Down Expand Up @@ -110,13 +109,14 @@ pub struct Rover {
}

impl Rover {
pub fn run_from_args() -> io::Result<()> {
pub fn run_from_args() -> RoverResult<()> {
Rover::parse().run()
}

pub fn run(&self) -> io::Result<()> {
pub fn run(&self) -> RoverResult<()> {
timber::init(self.log_level);
tracing::trace!(command_structure = ?self);
self.output_opts.validate_options();

// attempt to create a new `Session` to capture anonymous usage data
let rover_output = match Session::new(self) {
Expand Down Expand Up @@ -152,20 +152,13 @@ impl Rover {

match rover_output {
Ok(output) => {
match self.output_type {
OutputType::Plain => output.print()?,
OutputType::Json => JsonOutput::from(output).print()?,
}
self.output_opts.handle_output(output)?;

process::exit(0);
}
Err(error) => {
match self.output_type {
OutputType::Json => JsonOutput::from(error).print()?,
OutputType::Plain => {
tracing::debug!(?error);
error.print()?;
}
}
self.output_opts.handle_output(error)?;

process::exit(1);
}
}
Expand Down Expand Up @@ -199,15 +192,15 @@ impl Rover {
self.get_client_config()?,
self.get_git_context()?,
self.get_checks_timeout_seconds()?,
self.get_json(),
&self.output_opts,
),
Command::Template(command) => command.run(self.get_client_config()?),
Command::Readme(command) => command.run(self.get_client_config()?),
Command::Subgraph(command) => command.run(
self.get_client_config()?,
self.get_git_context()?,
self.get_checks_timeout_seconds()?,
self.get_json(),
&self.output_opts,
),
Command::Update(command) => {
command.run(self.get_rover_config()?, self.get_reqwest_client()?)
Expand All @@ -220,10 +213,6 @@ impl Rover {
}
}

pub(crate) fn get_json(&self) -> bool {
matches!(self.output_type, OutputType::Json)
}

pub(crate) fn get_rover_config(&self) -> RoverResult<Config> {
let override_home: Option<Utf8PathBuf> = self
.get_env_var(RoverEnvKey::ConfigHome)?
Expand Down Expand Up @@ -411,13 +400,19 @@ pub enum Command {
}

#[derive(ValueEnum, Debug, Serialize, Clone, Eq, PartialEq)]
pub enum OutputType {
pub enum RoverOutputFormatKind {
Plain,
Json,
}

impl Default for OutputType {
#[derive(ValueEnum, Debug, Serialize, Clone, Eq, PartialEq)]
pub enum RoverOutputKind {
RoverOutput,
RoverError,
}

impl Default for RoverOutputFormatKind {
fn default() -> Self {
OutputType::Plain
RoverOutputFormatKind::Plain
}
}
Loading