mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
bbbbbbbbbbbb
This commit is contained in:
parent
760816c81f
commit
30a86e1de5
3 changed files with 60 additions and 39 deletions
|
@ -29,14 +29,11 @@ where
|
|||
}
|
||||
|
||||
impl<'a, S> BaseArgumentBuilder<'a, S> {
|
||||
pub fn then(
|
||||
&mut self,
|
||||
command: Box<dyn ArgumentBuilder<S, Self>>,
|
||||
) -> Result<&mut Self, String> {
|
||||
pub fn then(&mut self, argument: Box<dyn CommandNode<S>>) -> Result<&mut Self, String> {
|
||||
if self.target.is_some() {
|
||||
return Err("Cannot add children to a redirected node".to_string());
|
||||
}
|
||||
self.command = Some(command);
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
@ -44,25 +41,25 @@ impl<'a, S> BaseArgumentBuilder<'a, S> {
|
|||
&self.arguments.get_children()
|
||||
}
|
||||
|
||||
pub fn executes(&mut self, command: dyn Command<S>) -> &mut Self {
|
||||
self.command = command;
|
||||
pub fn executes(&mut self, command: Box<dyn Command<S>>) -> &mut Self {
|
||||
self.command = Some(command);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn command(&self) -> dyn Command<S> {
|
||||
pub fn command(&self) -> Option<Box<dyn Command<S>>> {
|
||||
self.command
|
||||
}
|
||||
|
||||
pub fn requires(&mut self, requirement: &dyn Fn(&S) -> bool) -> &mut Self {
|
||||
pub fn requires(&mut self, requirement: Box<dyn Fn(&S) -> bool>) -> &mut Self {
|
||||
self.requirement = requirement;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn requirement(&self) -> dyn Fn(&S) -> bool {
|
||||
pub fn requirement(&self) -> Box<dyn Fn(&S) -> bool> {
|
||||
self.requirement
|
||||
}
|
||||
|
||||
pub fn redirect(&mut self, target: &dyn CommandNode<S>) -> &mut Self {
|
||||
pub fn redirect(&mut self, target: Box<dyn CommandNode<S>>) -> &mut Self {
|
||||
self.forward(target, None, false)
|
||||
}
|
||||
|
||||
|
@ -85,8 +82,8 @@ impl<'a, S> BaseArgumentBuilder<'a, S> {
|
|||
|
||||
pub fn forward(
|
||||
&mut self,
|
||||
target: &dyn CommandNode<S>,
|
||||
modifier: Option<&dyn RedirectModifier<S>>,
|
||||
target: Box<dyn CommandNode<S>>,
|
||||
modifier: Option<Box<dyn RedirectModifier<S>>>,
|
||||
fork: bool,
|
||||
) -> Result<&mut Self, String> {
|
||||
if !self.arguments.get_children().is_empty() {
|
||||
|
@ -130,3 +127,16 @@ impl<'a, S> BaseArgumentBuilder<'a, S> {
|
|||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Default for BaseArgumentBuilder<'_, S> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
arguments: Default::default(),
|
||||
command: Default::default(),
|
||||
requirement: Default::default(),
|
||||
target: Default::default(),
|
||||
modifier: Default::default(),
|
||||
forks: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
use super::argument_builder::{ArgumentBuilder, BaseArgumentBuilder};
|
||||
use crate::{
|
||||
arguments::argument_type::ArgumentType,
|
||||
tree::{command_node::CommandNode, literal_command_node::LiteralCommandNode},
|
||||
command::Command,
|
||||
redirect_modifier::RedirectModifier,
|
||||
tree::{
|
||||
command_node::CommandNode, literal_command_node::LiteralCommandNode,
|
||||
root_command_node::RootCommandNode,
|
||||
},
|
||||
};
|
||||
|
||||
use super::argument_builder::{ArgumentBuilder, BaseArgumentBuilder};
|
||||
|
||||
pub struct LiteralArgumentBuilder<'a, S> {
|
||||
literal: String,
|
||||
arguments: RootCommandNode<'a, S>,
|
||||
command: Option<Box<dyn Command<S>>>,
|
||||
requirement: Box<dyn Fn(&S) -> bool>,
|
||||
target: Option<Box<dyn CommandNode<S>>>,
|
||||
modifier: Option<Box<dyn RedirectModifier<S>>>,
|
||||
forks: bool,
|
||||
|
||||
pub base: BaseArgumentBuilder<'a, S>,
|
||||
literal: String,
|
||||
}
|
||||
|
||||
impl<'a, S> LiteralArgumentBuilder<'a, S> {
|
||||
|
@ -31,10 +40,10 @@ where
|
|||
fn build(self) -> Box<dyn CommandNode<S>> {
|
||||
let result = LiteralCommandNode::new(self.literal, self.base.build());
|
||||
|
||||
for argument in self.base.arguments {
|
||||
for argument in self.base.arguments() {
|
||||
result.add_child(argument);
|
||||
}
|
||||
|
||||
result
|
||||
Box::new(result)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,16 @@ use std::any::Any;
|
|||
use super::argument_builder::BaseArgumentBuilder;
|
||||
|
||||
pub struct RequiredArgumentBuilder<'a, S> {
|
||||
// private final String name;
|
||||
// private final ArgumentType<T> type;
|
||||
// private SuggestionProvider<S> suggestionsProvider = null;
|
||||
arguments: RootCommandNode<'a, S>,
|
||||
command: Option<Box<dyn Command<S>>>,
|
||||
requirement: Box<dyn Fn(&S) -> bool>,
|
||||
target: Option<Box<dyn CommandNode<S>>>,
|
||||
modifier: Option<Box<dyn RedirectModifier<S>>>,
|
||||
forks: bool,
|
||||
|
||||
name: String,
|
||||
type_: Box<dyn ArgumentType<Into = dyn Any>>,
|
||||
suggestions_provider: Option<&'a dyn SuggestionProvider<S>>,
|
||||
|
||||
pub base: BaseArgumentBuilder<'a, S>,
|
||||
suggestions_provider: Option<Box<dyn SuggestionProvider<S>>>,
|
||||
}
|
||||
|
||||
impl<'a, S> RequiredArgumentBuilder<'a, S> {
|
||||
|
@ -24,29 +26,29 @@ impl<'a, S> RequiredArgumentBuilder<'a, S> {
|
|||
name,
|
||||
type_: type_,
|
||||
suggestions_provider: None,
|
||||
base: BaseArgumentBuilder::new(name, type_),
|
||||
base: BaseArgumentBuilder::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn argument(name: String, type_: dyn ArgumentType<Into = dyn Any>) -> Self {
|
||||
pub fn argument(name: String, type_: Box<dyn ArgumentType<Into = dyn Any>>) -> Self {
|
||||
Self::new(name, type_)
|
||||
}
|
||||
|
||||
pub fn suggests(mut self, provider: &dyn SuggestionProvider<S>) -> Self {
|
||||
pub fn suggests(mut self, provider: Box<dyn SuggestionProvider<S>>) -> Self {
|
||||
self.suggestions_provider = Some(provider);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn suggestions_provider(&self) -> Option<&dyn SuggestionProvider<S>> {
|
||||
self.suggestions_provider.as_ref()
|
||||
pub fn suggestions_provider(&self) -> Option<Box<dyn SuggestionProvider<S>>> {
|
||||
self.suggestions_provider
|
||||
}
|
||||
|
||||
pub fn get_type(&self) -> &dyn ArgumentType<Into = dyn Any> {
|
||||
pub fn get_type(&self) -> Box<dyn ArgumentType<Into = dyn Any>> {
|
||||
self.type_
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
self.name
|
||||
&self.name
|
||||
}
|
||||
|
||||
// final ArgumentCommandNode<S> result = new ArgumentCommandNode<>(getName(), getType(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getSuggestionsProvider());
|
||||
|
@ -59,19 +61,19 @@ impl<'a, S> RequiredArgumentBuilder<'a, S> {
|
|||
pub fn build(self) -> ArgumentCommandNode<'a, S> {
|
||||
let result = ArgumentCommandNode {
|
||||
name: self.name,
|
||||
type_: &self.type_,
|
||||
type_: self.type_,
|
||||
base: BaseCommandNode {
|
||||
command: self.base.command,
|
||||
requirement: self.base.requirement,
|
||||
redirect: self.base.redirect,
|
||||
modifier: self.base.modifier,
|
||||
command: self.base.command(),
|
||||
requirement: self.base.requirement(),
|
||||
redirect: self.base.get_redirect(),
|
||||
modifier: self.base.get_redirect_modifier(),
|
||||
forks: self.base.forks,
|
||||
..BaseCommandNode::default()
|
||||
},
|
||||
custom_suggestions: self.base.custom_suggestions,
|
||||
};
|
||||
|
||||
for argument in self.base.arguments {
|
||||
for argument in self.base.arguments() {
|
||||
result.add_child(argument);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue