Skip to content

Commit

Permalink
starlark command: Remove opaque from names
Browse files Browse the repository at this point in the history
Summary: And better explain what these actually are. A little bit of consistent naming goes a long way

Reviewed By: samkevich

Differential Revision: D59840488

fbshipit-source-id: c94406d58ec50660afff04cefb3ee708af2eb829
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Jul 18, 2024
1 parent d2aef7d commit 37a44bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions app/buck2_starlark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ pub mod typecheck;
#[clap(name = "starlark", about = "Run Starlark operations")]
pub enum StarlarkCommand {
#[clap(flatten)]
Opaque(StarlarkOpaqueCommand),
Opaque(StarlarkSubcommand),
DebugAttach(StarlarkDebugAttachCommand),
}

// Used for subcommands that follow `buck2 audit`'s "opaque" pattern where the command object is serialized
// to the daemon and deserialized there and has a `server_execute()` on the Command object itself (as opposed
// to using structured endpoints in the daemon protocol).
#[derive(Debug, clap::Subcommand, serde::Serialize, serde::Deserialize)]
pub enum StarlarkOpaqueCommand {
pub enum StarlarkSubcommand {
Lint(StarlarkLintCommand),
Typecheck(StarlarkTypecheckCommand),
}

impl StarlarkOpaqueCommand {
impl StarlarkSubcommand {
fn as_client_subcommand(&self) -> &dyn StarlarkClientSubcommand {
match self {
StarlarkOpaqueCommand::Lint(cmd) => cmd,
StarlarkOpaqueCommand::Typecheck(cmd) => cmd,
StarlarkSubcommand::Lint(cmd) => cmd,
StarlarkSubcommand::Typecheck(cmd) => cmd,
}
}
}
Expand All @@ -79,7 +79,7 @@ pub struct StarlarkCommandCommonOptions {
}

#[async_trait]
impl StreamingCommand for StarlarkOpaqueCommand {
impl StreamingCommand for StarlarkSubcommand {
const COMMAND_NAME: &'static str = "starlark";

/// Starlark subcommands are all implemented as a generic request to the buckd server that will deserialize the command object.
Expand Down
12 changes: 6 additions & 6 deletions app/buck2_starlark_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use buck2_events::dispatch::span_async;
use buck2_server_ctx::command_end::command_end;
use buck2_server_ctx::ctx::ServerCommandContextTrait;
use buck2_server_ctx::partial_result_dispatcher::PartialResultDispatcher;
use buck2_starlark::StarlarkOpaqueCommand;
use buck2_starlark::StarlarkSubcommand;

#[async_trait]
pub(crate) trait StarlarkOpaqueSubcommand: Send + Sync + 'static {
pub(crate) trait StarlarkServerSubcommand: Send + Sync + 'static {
async fn server_execute(
&self,
server_ctx: &dyn ServerCommandContextTrait,
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn parse_command_and_execute(
partial_result_dispatcher: PartialResultDispatcher<buck2_cli_proto::StdoutBytes>,
req: buck2_cli_proto::GenericRequest,
) -> anyhow::Result<()> {
let command: StarlarkOpaqueCommand = serde_json::from_str(&req.serialized_opts)?;
let command: StarlarkSubcommand = serde_json::from_str(&req.serialized_opts)?;
as_server_subcommand(&command)
.server_execute(
context,
Expand All @@ -83,9 +83,9 @@ async fn parse_command_and_execute(
.await
}

fn as_server_subcommand(cmd: &StarlarkOpaqueCommand) -> &dyn StarlarkOpaqueSubcommand {
fn as_server_subcommand(cmd: &StarlarkSubcommand) -> &dyn StarlarkServerSubcommand {
match cmd {
StarlarkOpaqueCommand::Lint(cmd) => cmd,
StarlarkOpaqueCommand::Typecheck(cmd) => cmd,
StarlarkSubcommand::Lint(cmd) => cmd,
StarlarkSubcommand::Typecheck(cmd) => cmd,
}
}
4 changes: 2 additions & 2 deletions app/buck2_starlark_server/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use starlark::syntax::AstModule;

use crate::util::environment::Environment;
use crate::util::paths::starlark_files;
use crate::StarlarkOpaqueSubcommand;
use crate::StarlarkServerSubcommand;

/// The cache of names for a path, keyed by its CellName and its path type.
struct Cache<'a> {
Expand Down Expand Up @@ -102,7 +102,7 @@ async fn lint_file(
}

#[async_trait]
impl StarlarkOpaqueSubcommand for StarlarkLintCommand {
impl StarlarkServerSubcommand for StarlarkLintCommand {
async fn server_execute(
&self,
server_ctx: &dyn ServerCommandContextTrait,
Expand Down
4 changes: 2 additions & 2 deletions app/buck2_starlark_server/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use starlark::typing::Interface;

use crate::util::environment::Environment;
use crate::util::paths::starlark_files;
use crate::StarlarkOpaqueSubcommand;
use crate::StarlarkServerSubcommand;

struct Cache<'a> {
// Things we have access to get information
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> Cache<'a> {
}

#[async_trait]
impl StarlarkOpaqueSubcommand for StarlarkTypecheckCommand {
impl StarlarkServerSubcommand for StarlarkTypecheckCommand {
async fn server_execute(
&self,
server_ctx: &dyn ServerCommandContextTrait,
Expand Down

0 comments on commit 37a44bb

Please sign in to comment.