Skip to content

Commit de1f721

Browse files
authored
Adding initial scaffolding for init command behind cargo flag (#2443)
<!-- First, 🌠 thank you 🌠 for taking the time to consider a contribution to Apollo! Here are some important details to follow: * ⏰ Your time is important To save your precious time, if the contribution you are making will take more than an hour, please make sure it has been discussed in an issue first. This is especially true for feature requests! * 💡 Features Feature requests can be created and discussed within a GitHub Issue. Be sure to search for existing feature requests (and related issues!) prior to opening a new request. If an existing issue covers the need, please upvote that issue by using the 👍 emote, rather than opening a new issue. * 🕷 Bug fixes These can be created and discussed in this repository. When fixing a bug, please _try_ to add a test which verifies the fix. If you cannot, you should still submit the PR but we may still ask you (and help you!) to create a test. * 📖 Contribution guidelines Follow https://github.com/apollographql/rover/blob/HEAD/CONTRIBUTING.md when submitting a pull request. Make sure existing tests still pass, and add tests for all new behavior. * ✏️ Explain your pull request Describe the big picture of your changes here to communicate to what your pull request is meant to accomplish. Provide 🔗 links 🔗 to associated issues! We hope you will find this to be a positive experience! Open source contribution can be intimidating and we hope to alleviate that pain as much as possible. Without following these guidelines, you may be missing context that can help you succeed with your contribution, which is why we encourage discussion first. Ultimately, there is no guarantee that we will be able to merge your pull-request, but by following these guidelines we can try to avoid disappointment. --> This is the initial scaffolding for a new `init` command as a new module. This command is behind the `init` cargo feature flag Run: `cargo run --features init init` or `cargo --features init rover init` to test command locally This command currently only prints a welcome message to the terminal.
1 parent cafba3b commit de1f721

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ default = ["composition-js"]
4646
# because of this GitHub issue: https://github.com/denoland/deno/issues/3711
4747
composition-js = []
4848

49+
# this feature exists to enable the
50+
# init command
51+
init = []
52+
4953
### cross-workspace dependencies
5054
# these dependencies can be used by any other workspace crate by specifying the dependency like so:
5155
# my-dependency = { workspace = true }

src/cli.rs

+6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ impl Rover {
177177
}
178178

179179
match &self.command {
180+
#[cfg(feature = "init")]
181+
Command::Init(command) => command.run().await,
180182
Command::Cloud(command) => command.run(self.get_client_config()?).await,
181183
Command::Config(command) => command.run(self.get_client_config()?).await,
182184
Command::Contract(command) => command.run(self.get_client_config()?).await,
@@ -355,6 +357,10 @@ impl Rover {
355357

356358
#[derive(Debug, Serialize, Parser)]
357359
pub enum Command {
360+
/// Initialize a GraphQL API project using Apollo Federation with Apollo Router
361+
#[cfg(feature = "init")]
362+
Init(command::Init),
363+
358364
/// Cloud configuration commands
359365
Cloud(command::Cloud),
360366

src/command/init/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use clap::Parser;
2+
use serde::Serialize;
3+
4+
use crate::{RoverOutput, RoverResult};
5+
6+
#[derive(Debug, Serialize, Parser)]
7+
pub struct Init {}
8+
9+
impl Init {
10+
pub async fn run(&self) -> RoverResult<RoverOutput> {
11+
println!("\nWelcome! This command helps you initialize a new GraphQL API project using Apollo Federation with Apollo Router.\n");
12+
13+
Ok(RoverOutput::EmptySuccess)
14+
}
15+
}

src/command/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod docs;
66
mod explain;
77
mod graph;
88
mod info;
9+
#[cfg(feature = "init")]
10+
mod init;
911
pub(crate) mod install;
1012
mod license;
1113
#[cfg(feature = "composition-js")]
@@ -26,6 +28,8 @@ pub use docs::Docs;
2628
pub use explain::Explain;
2729
pub use graph::Graph;
2830
pub use info::Info;
31+
#[cfg(feature = "init")]
32+
pub use init::Init;
2933
pub use install::Install;
3034
pub use license::License;
3135
#[cfg(feature = "composition-js")]

0 commit comments

Comments
 (0)