Skip to main content

ServerArgs

Struct ServerArgs 

Source
pub struct ServerArgs {
    pub command: Option<ServerCommand>,
    pub table: Option<String>,
    pub port: Option<u16>,
    pub no_open: bool,
    pub restart: bool,
    pub api_only: bool,
}
Expand description

The arguments the editor’s subcommand takes. A repository whose subcommand takes arguments of its own flattens this into its own Args struct.

Fields§

§command: Option<ServerCommand>

Subcommand. Omit to launch (or reuse) the server, the default.

§table: Option<String>

Table or view to open by name. Defaults to the app’s front page.

§port: Option<u16>

Port to bind on 127.0.0.1. Defaults to the app’s own port, so two editors on one machine do not collide.

§no_open: bool

Do not open a browser; just run the server.

§restart: bool

Shut down any server already running on the port and start a fresh one (e.g. to pick up a newly built binary). Without this, an existing server for this app is reused.

§api_only: bool

Development mode: serve only /api in the foreground (no embedded UI, no browser). Vite serves the UI and proxies /api here.

Implementations§

Source§

impl ServerArgs

Source

pub fn augment_help( command: Command, default_page: &str, default_port: u16, ) -> Command

Put the consuming app’s own defaults into the help for table and --port.

The two arguments default to something only the Server knows: the app’s front page and the port it was built with. Help, though, is rendered by clap before run is ever reached, so the text has to be rewritten on the way in. Build the command, hand it here, and parse from what comes back:

let command = ServerArgs::augment_help(Cli::command(), "books", 8788);
let cli = Cli::from_arg_matches(&command.get_matches())?;

Where the arguments sit does not matter: the whole command tree is walked. A command is rewritten only where it holds both table and port and both still carry this crate’s own help, which is what flattening ServerArgs leaves behind. A repository’s own --port on some other subcommand keeps its own wording, and so does one whose help the repository has already rewritten. Nothing but the help changes.

Examples found in repository?
examples/library/main.rs (line 1042)
1038fn main() -> anyhow::Result<()> {
1039    // The tables belong to the example, not to whoever ran it.
1040    std::env::set_current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/library"))?;
1041
1042    let command = ServerArgs::augment_help(Cli::command(), "the front page", DEFAULT_PORT);
1043    let cli = Cli::from_arg_matches(&command.get_matches())?;
1044
1045    match cli.command {
1046        Command::Web(args) => Server::new(Library {
1047            books: Books,
1048            genres: Genres,
1049            branches: Branches,
1050            on_loan: OnLoan,
1051            branch_cards: BranchCards,
1052            branch_detail: BranchDetail,
1053        })
1054        .child_env("LIBRARY_EXAMPLE_CHILD")
1055        .default_port(DEFAULT_PORT)
1056        .run(args),
1057    }
1058}

Trait Implementations§

Source§

impl Args for ServerArgs

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl Debug for ServerArgs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromArgMatches for ServerArgs

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.