Skip to content
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 apps/cli/crates/onequery-cli/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ onequery query validate [OPTIONS] --source <SOURCE_KEY> --input <PATH|->
}

#[derive(Debug, Clone, Args, Eq, PartialEq)]
pub(crate) struct UseArgs {
pub(crate) struct ApiArgs {
/// Describe or execute this connected source API.
#[arg(long, value_name = "SOURCE_KEY")]
pub source: String,
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/crates/onequery-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod raw;
#[path = "../cli_tests.rs"]
mod tests;

pub(crate) use args::ApiArgs;
pub(crate) use args::AuthImportArgs;
pub(crate) use args::AuthSessionSubcommand;
pub(crate) use args::AuthSubcommand;
Expand All @@ -27,7 +28,6 @@ pub(crate) use args::ReadArgs;
pub(crate) use args::RestoreArgs;
pub(crate) use args::SourceConnectArgs;
pub(crate) use args::SourceSubcommand;
pub(crate) use args::UseArgs;
pub(crate) use model::Command;
pub(crate) use model::ConfigCommand;
pub(crate) use model::GatewayCommand;
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/crates/onequery-cli/src/cli/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::config::RawCliConfigOverrides;
use crate::output::EffectiveOutputMode;
use crate::output::TerminalOutput;

use super::args::ApiArgs;
use super::args::AuthSessionSubcommand;
use super::args::AuthSubcommand;
use super::args::BackupArgs;
Expand All @@ -10,7 +11,6 @@ use super::args::OrgSubcommand;
use super::args::QuerySubcommand;
use super::args::RestoreArgs;
use super::args::SourceSubcommand;
use super::args::UseArgs;

#[derive(Debug)]
pub(crate) enum ParseOutcome {
Expand Down Expand Up @@ -46,7 +46,7 @@ pub(crate) enum Command {
Restore(RestoreArgs),
Gateway(GatewayCommand),
Upgrade,
Use(UseArgs),
Api(ApiArgs),
Debug(DebugSubcommand),
}

Expand Down Expand Up @@ -78,7 +78,7 @@ impl Command {
Self::Gateway(GatewayCommand::Status) => "gateway status",
Self::Gateway(GatewayCommand::Logs) => "gateway logs",
Self::Upgrade => "upgrade",
Self::Use(_) => "use",
Self::Api(_) => "api",
Self::Debug(DebugSubcommand::Config) => "debug config",
Self::Debug(DebugSubcommand::AuthSession) => "debug auth-session",
}
Expand Down
12 changes: 6 additions & 6 deletions apps/cli/crates/onequery-cli/src/cli/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use clap::Subcommand;

use crate::output::RequestedOutputMode;

use super::args::ApiArgs;
use super::args::AuthSubcommand;
use super::args::BackupArgs;
use super::args::DebugSubcommand;
use super::args::OrgSubcommand;
use super::args::QuerySubcommand;
use super::args::RestoreArgs;
use super::args::SourceSubcommand;
use super::args::UseArgs;
use super::model::Command;
use super::model::ConfigCommand;
use super::model::GatewayCommand;
Expand Down Expand Up @@ -124,10 +124,10 @@ pub(super) enum RawCommand {
Upgrade,
/// Describe or execute a connected source API.
#[command(override_usage = "\
onequery use [OPTIONS] --source <SOURCE_KEY>
onequery use [OPTIONS] --source <SOURCE_KEY> [<TARGET>]
onequery use [OPTIONS] --source <SOURCE_KEY> --op <OPERATION> [<TARGET>]")]
Use(UseArgs),
onequery api [OPTIONS] --source <SOURCE_KEY>
onequery api [OPTIONS] --source <SOURCE_KEY> [<TARGET>]
onequery api [OPTIONS] --source <SOURCE_KEY> --op <OPERATION> [<TARGET>]")]
Api(ApiArgs),
/// Inspect local CLI state and diagnostics.
#[command(hide = true, arg_required_else_help(true))]
Debug {
Expand Down Expand Up @@ -180,7 +180,7 @@ impl From<RawCommand> for Command {
RawCommand::Restore(args) => Self::Restore(args),
RawCommand::Gateway { action } => Self::Gateway(action.into()),
RawCommand::Upgrade => Self::Upgrade,
RawCommand::Use(args) => Self::Use(args),
RawCommand::Api(args) => Self::Api(args),
RawCommand::Debug { action } => Self::Debug(action),
}
}
Expand Down
26 changes: 13 additions & 13 deletions apps/cli/crates/onequery-cli/src/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::output::EffectiveOutputMode;
use crate::output::RequestedOutputMode;
use crate::transport::source_connect_provider::SourceConnectProvider;

use super::ApiArgs;
use super::AuthImportArgs;
use super::AuthSessionSubcommand;
use super::Command;
Expand All @@ -23,7 +24,6 @@ use super::QueryInputArgs;
use super::QueryResultWindowArgs;
use super::QuerySubcommand;
use super::ReadArgs;
use super::UseArgs;

fn argv(args: &[&str]) -> Vec<OsString> {
args.iter().map(OsString::from).collect()
Expand Down Expand Up @@ -71,8 +71,8 @@ fn query_help_output_snapshot_targets_query_surface() {
}

#[test]
fn use_help_output_snapshot_targets_use_surface() {
assert_snapshot!(rendered_display(&["onequery", "use", "--help"]));
fn api_help_output_snapshot_targets_api_surface() {
assert_snapshot!(rendered_display(&["onequery", "api", "--help"]));
}

#[test]
Expand Down Expand Up @@ -348,15 +348,15 @@ fn normalize_command_line_redacts_raw_config_override_values() {
}

#[test]
fn parse_invocation_accepts_use_describe_surface() {
let invocation = parse_invocation(&["onequery", "use", "--source", "sentry-prod"]);
fn parse_invocation_accepts_api_describe_surface() {
let invocation = parse_invocation(&["onequery", "api", "--source", "sentry-prod"]);

assert_eq!(
match invocation.command {
Command::Use(args) => args,
other => panic!("expected use command, got {other:?}"),
Command::Api(args) => args,
other => panic!("expected api command, got {other:?}"),
},
UseArgs {
ApiArgs {
source: "sentry-prod".to_owned(),
op: None,
target: None,
Expand All @@ -377,10 +377,10 @@ fn parse_invocation_accepts_use_describe_surface() {
}

#[test]
fn parse_invocation_accepts_use_execute_flags() {
fn parse_invocation_accepts_api_execute_flags() {
let invocation = parse_invocation(&[
"onequery",
"use",
"api",
"--source",
"github-prod",
"--op",
Expand Down Expand Up @@ -411,10 +411,10 @@ fn parse_invocation_accepts_use_execute_flags() {

assert_eq!(
match invocation.command {
Command::Use(args) => args,
other => panic!("expected use command, got {other:?}"),
Command::Api(args) => args,
other => panic!("expected api command, got {other:?}"),
},
UseArgs {
ApiArgs {
source: "github-prod".to_owned(),
op: Some("fetch-api".to_owned()),
target: Some("/repos/acme/widgets/pulls/1".to_owned()),
Expand Down
12 changes: 6 additions & 6 deletions apps/cli/crates/onequery-cli/src/commands/json_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ mod tests {
fn parse_org_scoped_json_input_rejects_non_object_payloads() {
let error = parse_org_scoped_json_input(
r#"["not","an","object"]"#,
&test_context("onequery use --source github --input <excerpt>"),
"invalid use input",
"use input",
|| vec!["onequery use --source github".to_owned()],
&test_context("onequery api --source github --input <excerpt>"),
"invalid api input",
"api input",
|| vec!["onequery api --source github".to_owned()],
)
.expect_err("expected non-object input to be rejected");

assert_eq!(error.title, "invalid use input");
assert_eq!(error.why, "use input must be one JSON object");
assert_eq!(error.title, "invalid api input");
assert_eq!(error.why, "api input must be one JSON object");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/crates/onequery-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where
gateway::execute(gateway_command, context, runtime).await
}
Command::Upgrade => upgrade::execute(context, runtime).await,
Command::Use(use_args) => source_api::execute(&use_args, context, runtime).await,
Command::Api(api_args) => source_api::execute(&api_args, context, runtime).await,
Command::Debug(debug_command) => debug::execute(&debug_command, context, runtime).await,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use onequery_cli_core::error::ErrorStage;
use tokio::fs;
use tokio::io::AsyncReadExt;

use crate::cli::UseArgs;
use crate::cli::ApiArgs;
use crate::path_utils::resolve_user_path_for_cli;

use super::CommandContext;

pub(super) fn has_execute_intent_flags(args: &UseArgs) -> bool {
pub(super) fn has_execute_intent_flags(args: &ApiArgs) -> bool {
args.op.is_some()
|| args.target.is_some()
|| args.method.is_some()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ mod tests {

fn context() -> CommandContext {
CommandContext {
command_line: "onequery use --source github-prod".to_owned(),
command_line: "onequery api --source github-prod".to_owned(),
base_url: default_base_url(),
request_id: None,
resolved_org: Some("acme".to_owned()),
Expand Down
50 changes: 25 additions & 25 deletions apps/cli/crates/onequery-cli/src/commands/source_api/intent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use onequery_cli_core::error::CliError;

use crate::cli::UseArgs;
use crate::cli::ApiArgs;
use crate::transport::source_api::SourceApiDescriptor;

use super::CommandContext;
Expand All @@ -17,7 +17,7 @@ pub(super) enum ResolvedIntent {
}

pub(super) fn resolve_intent(
args: &UseArgs,
args: &ApiArgs,
descriptor: &SourceApiDescriptor,
context: &CommandContext,
) -> Result<ResolvedIntent, CliError> {
Expand Down Expand Up @@ -80,7 +80,7 @@ fn is_selector_target(target: &str) -> bool {
mod tests {
use onequery_cli_core::error::ErrorStage;

use crate::cli::UseArgs;
use crate::cli::ApiArgs;
use crate::commands::ResolvedOrgSource;
use crate::config::default_base_url;
use crate::transport::source_api::SourceApiDescriptor;
Expand All @@ -92,7 +92,7 @@ mod tests {

#[test]
fn resolve_intent_describes_when_only_source_is_provided() {
let intent = resolve_intent(&use_args(), &descriptor(), &context())
let intent = resolve_intent(&api_args(), &descriptor(), &context())
.expect("expected bare source usage to describe");

assert_eq!(intent, ResolvedIntent::Describe);
Expand All @@ -101,9 +101,9 @@ mod tests {
#[test]
fn resolve_intent_executes_when_explicit_operation_is_provided() {
let intent = resolve_intent(
&UseArgs {
&ApiArgs {
op: Some(" fetch ".to_owned()),
..use_args()
..api_args()
},
&descriptor(),
&context(),
Expand All @@ -122,17 +122,17 @@ mod tests {
#[test]
fn resolve_intent_describes_when_only_render_flags_are_provided() {
for args in [
UseArgs {
ApiArgs {
include: true,
..use_args()
..api_args()
},
UseArgs {
ApiArgs {
silent: true,
..use_args()
..api_args()
},
UseArgs {
ApiArgs {
jq: Some(".items[0]".to_owned()),
..use_args()
..api_args()
},
] {
let intent = resolve_intent(&args, &descriptor(), &context())
Expand All @@ -145,9 +145,9 @@ mod tests {
#[test]
fn resolve_intent_rejects_execute_flags_without_operation_or_selector() {
let error = resolve_intent(
&UseArgs {
&ApiArgs {
method: Some("POST".to_owned()),
..use_args()
..api_args()
},
&descriptor(),
&context(),
Expand All @@ -164,9 +164,9 @@ mod tests {
#[test]
fn resolve_intent_treats_bare_target_as_operation() {
let intent = resolve_intent(
&UseArgs {
&ApiArgs {
target: Some("search".to_owned()),
..use_args()
..api_args()
},
&descriptor(),
&context(),
Expand All @@ -185,9 +185,9 @@ mod tests {
#[test]
fn resolve_intent_treats_path_target_as_selector() {
let intent = resolve_intent(
&UseArgs {
&ApiArgs {
target: Some("/pulls".to_owned()),
..use_args()
..api_args()
},
&descriptor(),
&context(),
Expand All @@ -206,9 +206,9 @@ mod tests {
#[test]
fn resolve_intent_treats_url_target_as_selector() {
let intent = resolve_intent(
&UseArgs {
&ApiArgs {
target: Some("https://api.github.com/repos/acme/widgets/pulls".to_owned()),
..use_args()
..api_args()
},
&descriptor(),
&context(),
Expand All @@ -227,9 +227,9 @@ mod tests {
#[test]
fn resolve_intent_rejects_selector_target_without_default_path_operation() {
let error = resolve_intent(
&UseArgs {
&ApiArgs {
target: Some("/pulls".to_owned()),
..use_args()
..api_args()
},
&descriptor_without_default_path_operation(),
&context(),
Expand Down Expand Up @@ -267,7 +267,7 @@ mod tests {

fn context() -> CommandContext {
CommandContext {
command_line: "onequery use --source github-prod".to_owned(),
command_line: "onequery api --source github-prod".to_owned(),
base_url: default_base_url(),
request_id: None,
resolved_org: Some("acme".to_owned()),
Expand All @@ -276,8 +276,8 @@ mod tests {
}
}

fn use_args() -> UseArgs {
UseArgs {
fn api_args() -> ApiArgs {
ApiArgs {
source: "github-prod".to_owned(),
op: None,
target: None,
Expand Down
Loading
Loading