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: boolDo not open a browser; just run the server.
restart: boolShut 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: boolDevelopment mode: serve only /api in the foreground (no embedded UI,
no browser). Vite serves the UI and proxies /api here.
Implementations§
Source§impl ServerArgs
impl ServerArgs
Sourcepub fn augment_help(
command: Command,
default_page: &str,
default_port: u16,
) -> Command
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?
678fn main() -> anyhow::Result<()> {
679 // The tables belong to the example, not to whoever ran it.
680 std::env::set_current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/library"))?;
681
682 let command = ServerArgs::augment_help(Cli::command(), "the front page", DEFAULT_PORT);
683 let cli = Cli::from_arg_matches(&command.get_matches())?;
684
685 match cli.command {
686 Command::Web(args) => Server::new(Library {
687 books: Books,
688 genres: Genres,
689 branches: Branches,
690 on_loan: OnLoan,
691 })
692 .child_env("LIBRARY_EXAMPLE_CHILD")
693 .default_port(DEFAULT_PORT)
694 .run(args),
695 }
696}Trait Implementations§
Source§impl Args for ServerArgs
impl Args for ServerArgs
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl Debug for ServerArgs
impl Debug for ServerArgs
Source§impl FromArgMatches for ServerArgs
impl FromArgMatches for ServerArgs
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.