Skip to content

Commit d26ebd8

Browse files
chore: factors out SchemaOpt
1 parent 7e8a740 commit d26ebd8

File tree

6 files changed

+45
-34
lines changed

6 files changed

+45
-34
lines changed

src/command/graph/check.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,22 @@ use rover_client::operations::graph::check::{self, GraphCheckInput};
55
use rover_client::shared::{CheckConfig, GitContext, ValidationPeriod};
66

77
use crate::command::RoverOutput;
8-
use crate::options::GraphRefOpt;
8+
use crate::options::{GraphRefOpt, ProfileOpt, SchemaOpt};
99
use crate::utils::client::StudioClientConfig;
10-
use crate::utils::parsers::{
11-
parse_file_descriptor, parse_query_count_threshold, parse_query_percentage_threshold,
12-
FileDescriptorType,
13-
};
10+
use crate::utils::parsers::{parse_query_count_threshold, parse_query_percentage_threshold};
1411
use crate::Result;
1512

1613
#[derive(Debug, Serialize, StructOpt)]
1714
pub struct Check {
1815
#[structopt(flatten)]
1916
graph: GraphRefOpt,
2017

21-
/// Name of configuration profile to use
22-
#[structopt(long = "profile", default_value = "default")]
23-
#[serde(skip_serializing)]
24-
profile_name: String,
18+
#[structopt(flatten)]
19+
profile: ProfileOpt,
2520

26-
/// The schema file to check. You can pass `-` to use stdin instead of a file.
27-
#[structopt(long, short = "s", parse(try_from_str = parse_file_descriptor))]
21+
#[structopt(flatten)]
2822
#[serde(skip_serializing)]
29-
schema: FileDescriptorType,
23+
schema: SchemaOpt,
3024

3125
/// The minimum number of times a query or mutation must have been executed
3226
/// in order to be considered in the check operation
@@ -50,7 +44,7 @@ impl Check {
5044
client_config: StudioClientConfig,
5145
git_context: GitContext,
5246
) -> Result<RoverOutput> {
53-
let client = client_config.get_authenticated_client(&self.profile_name)?;
47+
let client = client_config.get_authenticated_client(&self.profile.profile_name)?;
5448
let proposed_schema = self
5549
.schema
5650
.read_file_descriptor("SDL", &mut std::io::stdin())?;

src/command/graph/publish.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use rover_client::operations::graph::publish::{self, GraphPublishInput};
66
use rover_client::shared::GitContext;
77

88
use crate::command::RoverOutput;
9-
use crate::options::{GraphRefOpt, ProfileOpt};
9+
use crate::options::{GraphRefOpt, ProfileOpt, SchemaOpt};
1010
use crate::utils::client::StudioClientConfig;
11-
use crate::utils::parsers::{parse_file_descriptor, FileDescriptorType};
1211
use crate::Result;
1312

1413
#[derive(Debug, Serialize, StructOpt)]
@@ -19,10 +18,9 @@ pub struct Publish {
1918
#[structopt(flatten)]
2019
profile: ProfileOpt,
2120

22-
/// The schema file to publish. You can pass `-` to use stdin instead of a file.
23-
#[structopt(long, short = "s", parse(try_from_str = parse_file_descriptor))]
21+
#[structopt(flatten)]
2422
#[serde(skip_serializing)]
25-
schema: FileDescriptorType,
23+
schema: SchemaOpt,
2624
}
2725

2826
impl Publish {

src/command/subgraph/check.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ use rover_client::operations::subgraph::check::{self, SubgraphCheckInput};
55
use rover_client::shared::{CheckConfig, GitContext, ValidationPeriod};
66

77
use crate::command::RoverOutput;
8-
use crate::options::{GraphRefOpt, ProfileOpt, SubgraphOpt};
8+
use crate::options::{GraphRefOpt, ProfileOpt, SchemaOpt, SubgraphOpt};
99
use crate::utils::client::StudioClientConfig;
10-
use crate::utils::parsers::{
11-
parse_file_descriptor, parse_query_count_threshold, parse_query_percentage_threshold,
12-
FileDescriptorType,
13-
};
10+
use crate::utils::parsers::{parse_query_count_threshold, parse_query_percentage_threshold};
1411
use crate::Result;
1512

1613
#[derive(Debug, Serialize, StructOpt)]
@@ -24,10 +21,9 @@ pub struct Check {
2421
#[structopt(flatten)]
2522
profile: ProfileOpt,
2623

27-
/// The schema file to check. You can pass `-` to use stdin instead of a file.
28-
#[structopt(long, short = "s", parse(try_from_str = parse_file_descriptor))]
24+
#[structopt(flatten)]
2925
#[serde(skip_serializing)]
30-
schema: FileDescriptorType,
26+
schema: SchemaOpt,
3127

3228
/// The minimum number of times a query or mutation must have been executed
3329
/// in order to be considered in the check operation

src/command/subgraph/publish.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ use serde::Serialize;
33
use structopt::StructOpt;
44

55
use crate::command::RoverOutput;
6-
use crate::options::{GraphRefOpt, ProfileOpt, SubgraphOpt};
7-
use crate::utils::{
8-
client::StudioClientConfig,
9-
parsers::{parse_file_descriptor, FileDescriptorType},
10-
};
6+
use crate::options::{GraphRefOpt, ProfileOpt, SchemaOpt, SubgraphOpt};
7+
use crate::utils::client::StudioClientConfig;
118
use crate::Result;
129

1310
use rover_client::operations::subgraph::publish::{self, SubgraphPublishInput};
@@ -24,10 +21,9 @@ pub struct Publish {
2421
#[structopt(flatten)]
2522
profile: ProfileOpt,
2623

27-
/// The schema file to publish. You can pass `-` to use stdin instead of a file.
28-
#[structopt(long, short = "s", parse(try_from_str = parse_file_descriptor))]
24+
#[structopt(flatten)]
2925
#[serde(skip_serializing)]
30-
schema: FileDescriptorType,
26+
schema: SchemaOpt,
3127

3228
/// Indicate whether to convert a non-federated graph into a subgraph
3329
#[structopt(short, long)]

src/options/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mod graph;
22
mod profile;
3+
mod schema;
34
mod subgraph;
45

56
pub(crate) use graph::GraphRefOpt;
67
pub(crate) use profile::ProfileOpt;
8+
pub(crate) use schema::SchemaOpt;
79
pub(crate) use subgraph::SubgraphOpt;

src/options/schema.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use structopt::StructOpt;
2+
3+
use crate::{
4+
utils::parsers::{parse_file_descriptor, FileDescriptorType},
5+
Result,
6+
};
7+
8+
use std::io::Read;
9+
10+
#[derive(Debug, StructOpt)]
11+
pub struct SchemaOpt {
12+
/// The schema file to check. You can pass `-` to use stdin instead of a file.
13+
#[structopt(long, short = "s", parse(try_from_str = parse_file_descriptor))]
14+
schema: FileDescriptorType,
15+
}
16+
17+
impl SchemaOpt {
18+
pub(crate) fn read_file_descriptor(
19+
&self,
20+
file_description: &str,
21+
stdin: &mut impl Read,
22+
) -> Result<String> {
23+
self.schema.read_file_descriptor(file_description, stdin)
24+
}
25+
}

0 commit comments

Comments
 (0)