Skip to content

Commit 9ccf891

Browse files
hotfix: resolve merge conflicts between main and sachin/new-contracts-commands (#1479)
Co-authored-by: Sachin D. Shinde <[email protected]>
1 parent 3a354ac commit 9ccf891

23 files changed

+495
-286
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1616
1717
## 📚 Documentation -->
1818

19+
# [0.10.1] - 2022-11-28
20+
21+
## 🚀 Features
22+
23+
- **Replace the '--output' option type with '--format' - @gocamille, #1413 fixes #1212**
24+
25+
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.
26+
27+
1928
# [0.10.0] - 2022-11-10
2029

2130
> Important: 1 potentially breaking change below, indicated by **❗ BREAKING ❗**

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ Options:
6969
-l, --log <LOG_LEVEL>
7070
Specify Rover's log level
7171

72+
--format <FORMAT_TYPE>
73+
Specify Rover's format type
74+
75+
[default: plain]
76+
[possible values: plain, json]
77+
7278
--output <OUTPUT_TYPE>
7379
Specify Rover's output type
7480
7581
[default: plain]
76-
[possible values: plain, json]
82+
[possible values: plain, json, filename]
7783

7884
--insecure-accept-invalid-certs
7985
Accept invalid certificates when performing HTTPS requests.

crates/rover-std/src/emoji.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum Emoji {
2020
Skull,
2121
Compose,
2222
Warn,
23+
Memo,
2324
}
2425

2526
impl Emoji {
@@ -42,6 +43,7 @@ impl Emoji {
4243
Skull => "💀 ",
4344
Compose => "🎶 ",
4445
Warn => "⚠️ ",
46+
Memo => "📝 ",
4547
}
4648
}
4749
}

docs/source/commands/graphs.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ You can also save the output to a local `.graphql` file like so:
6363

6464
```bash
6565
# Creates prod-schema.graphql or overwrites if it already exists
66-
rover graph fetch my-graph@my-variant > prod-schema.graphql
66+
rover graph fetch my-graph@my-variant --output prod-schema.graphql
6767
```
6868

6969
> For more on passing values via `stdout`, see [Conventions](../conventions#using-stdout).

docs/source/commands/readmes.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ By default, the README is output to `stdout`. You can also save the output to a
2929

3030
```bash
3131
# Creates README.md or overwrites if it already exists
32-
rover readme fetch my-graph@my-variant > README.md
32+
rover readme fetch my-graph@my-variant --output README.md
3333
```
3434

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

3737
```bash
38-
rover readme fetch my-graph@my-variant --output json
38+
rover readme fetch my-graph@my-variant --format json
3939
```
4040

4141
> For more on passing values via `stdout`, see [Conventions](../conventions#using-stdout).

docs/source/commands/subgraphs.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The subgraph must be reachable by Rover. The subgraph does _not_ need to have in
5454
5555
#### Watching for schema changes
5656

57-
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.
57+
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.
5858

5959
#### Including headers
6060

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

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

8989
> For more on passing values via `stdout`, see [Using `stdout`](../conventions#using-stdout).

docs/source/commands/supergraphs.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ You can save the schema output to a local `.graphql` file like so:
105105

106106
```bash
107107
# Creates prod-schema.graphql or overwrites if it already exists
108-
rover supergraph compose --config ./supergraph.yaml > prod-schema.graphql
108+
rover supergraph compose --config ./supergraph.yaml --output prod-schema.graphql
109109
```
110110

111111
> For more on passing values via `stdout`, see [Using `stdout`](../conventions#using-stdout).

docs/source/configuring.md

+28-7
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,24 @@ rover graph check my-graph@prod --schema ./schema.graphql --log debug
7474
If Rover log messages are unhelpful or unclear, please leave us feedback in an
7575
[issue on GitHub](https://github.com/apollographql/rover/issues/new/choose)!
7676

77-
## Output format
78-
79-
### `--output plain` (default)
77+
## Configuring output
8078

8179
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).
8280

83-
> For more on `stdout`, see [Conventions](./conventions/#using-stdout).
81+
> For more on `stdout`, see [Conventions](https://chat.openai.com/conventions/#using-stdout).
82+
83+
Every Rover command supports two options for configuring its output behavior:
84+
85+
- `--format`, for [setting the output format](#setting-output-format) (`plain` or `json`)
86+
- `--output`, for [writing a command's output to a file](#setting-output-location) instead of `stdout`
8487

85-
### `--output json`
88+
### JSON output
8689

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

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

233240
#### Example `jq` script
234241

235-
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.
242+
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.
243+
244+
### Writing to a file
245+
246+
The `--output` option enables you to specify a file destination for writing a Rover command's output:
247+
248+
```bash
249+
rover supergraph compose --output ./supergraph-schema.graphql --config ./supergraph.yaml
250+
```
251+
252+
If the specified file already exists, Rover overwrites it.
253+
254+
> **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).
255+
>
256+
> Current versions of Rover still support using `--output` like `--format`, but that support is deprecated and will be removed in a future release.
236257
237258
## Setting config storage location
238259

docs/source/conventions.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ All Rover commands that interact with the Apollo graph registry require a graph
3939

4040
### Using `stdout`
4141

42-
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`.
42+
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`.
4343

44-
To redirect Rover's output to a location other than your terminal, you can use the pipe `|` or output redirect `>` operators.
44+
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.
4545

4646
#### Pipe `|`
4747

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

5454
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).
5555

56-
#### Output redirect `>`
56+
#### Output to a file
5757

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

6060
```
61-
rover graph fetch my-graph@prod > schema.graphql
61+
rover graph fetch my-graph@prod --output schema.graphql
6262
```
6363

6464
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.
@@ -72,5 +72,3 @@ rover graph introspect http://localhost:4000 | rover graph check my-graph --sche
7272
```
7373

7474
In this example, the schema returned by `graph introspect` is then passed as the `--schema` option to `graph check`.
75-
76-
> Currently, `--schema` is the only Rover option that accepts a file path.

docs/source/migration.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ As a workaround, you might be able to use `cat` to combine multiple files and pa
144144

145145
### Machine-readable output
146146

147-
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).
147+
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).
148148

149-
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).
149+
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).
150150

151151
## Examples
152152

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

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

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

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

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

264-
265-
266264
### Pushing Subgraph Changes (with a config file)
267265

268266
```js

src/bin/rover.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use robot_panic::setup_panic;
22
use rover::cli::Rover;
33

44
#[calm_io::pipefail]
5-
fn main() -> std::io::Result<()> {
5+
fn main() -> Result<_, std::io::Error> {
66
setup_panic!(Metadata {
77
name: rover::PKG_NAME.into(),
88
version: rover::PKG_VERSION.into(),
99
authors: rover::PKG_AUTHORS.into(),
1010
homepage: rover::PKG_HOMEPAGE.into(),
1111
repository: rover::PKG_REPOSITORY.into()
1212
});
13-
Rover::run_from_args()
13+
Ok(Rover::run_from_args())
1414
}

src/cli.rs

+21-26
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use lazycell::{AtomicLazyCell, LazyCell};
44
use reqwest::blocking::Client;
55
use serde::Serialize;
66

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

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

6867
/// Accept invalid certificates when performing HTTPS requests.
6968
///
@@ -110,13 +109,14 @@ pub struct Rover {
110109
}
111110

112111
impl Rover {
113-
pub fn run_from_args() -> io::Result<()> {
112+
pub fn run_from_args() -> RoverResult<()> {
114113
Rover::parse().run()
115114
}
116115

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

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

153153
match rover_output {
154154
Ok(output) => {
155-
match self.output_type {
156-
OutputType::Plain => output.print()?,
157-
OutputType::Json => JsonOutput::from(output).print()?,
158-
}
155+
self.output_opts.handle_output(output)?;
156+
159157
process::exit(0);
160158
}
161159
Err(error) => {
162-
match self.output_type {
163-
OutputType::Json => JsonOutput::from(error).print()?,
164-
OutputType::Plain => {
165-
tracing::debug!(?error);
166-
error.print()?;
167-
}
168-
}
160+
self.output_opts.handle_output(error)?;
161+
169162
process::exit(1);
170163
}
171164
}
@@ -200,15 +193,15 @@ impl Rover {
200193
self.get_client_config()?,
201194
self.get_git_context()?,
202195
self.get_checks_timeout_seconds()?,
203-
self.get_json(),
196+
&self.output_opts,
204197
),
205198
Command::Template(command) => command.run(self.get_client_config()?),
206199
Command::Readme(command) => command.run(self.get_client_config()?),
207200
Command::Subgraph(command) => command.run(
208201
self.get_client_config()?,
209202
self.get_git_context()?,
210203
self.get_checks_timeout_seconds()?,
211-
self.get_json(),
204+
&self.output_opts,
212205
),
213206
Command::Update(command) => {
214207
command.run(self.get_rover_config()?, self.get_reqwest_client()?)
@@ -221,10 +214,6 @@ impl Rover {
221214
}
222215
}
223216

224-
pub(crate) fn get_json(&self) -> bool {
225-
matches!(self.output_type, OutputType::Json)
226-
}
227-
228217
pub(crate) fn get_rover_config(&self) -> RoverResult<Config> {
229218
let override_home: Option<Utf8PathBuf> = self
230219
.get_env_var(RoverEnvKey::ConfigHome)?
@@ -415,13 +404,19 @@ pub enum Command {
415404
}
416405

417406
#[derive(ValueEnum, Debug, Serialize, Clone, Eq, PartialEq)]
418-
pub enum OutputType {
407+
pub enum RoverOutputFormatKind {
419408
Plain,
420409
Json,
421410
}
422411

423-
impl Default for OutputType {
412+
#[derive(ValueEnum, Debug, Serialize, Clone, Eq, PartialEq)]
413+
pub enum RoverOutputKind {
414+
RoverOutput,
415+
RoverError,
416+
}
417+
418+
impl Default for RoverOutputFormatKind {
424419
fn default() -> Self {
425-
OutputType::Plain
420+
RoverOutputFormatKind::Plain
426421
}
427422
}

0 commit comments

Comments
 (0)