summaryrefslogtreecommitdiffstats
path: root/vendor/xflags/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/xflags/examples
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/xflags/examples')
-rw-r--r--vendor/xflags/examples/hello-generated.rs52
-rw-r--r--vendor/xflags/examples/hello.rs22
-rw-r--r--vendor/xflags/examples/longer.rs93
-rw-r--r--vendor/xflags/examples/non-utf8.rs43
4 files changed, 210 insertions, 0 deletions
diff --git a/vendor/xflags/examples/hello-generated.rs b/vendor/xflags/examples/hello-generated.rs
new file mode 100644
index 000000000..b82884859
--- /dev/null
+++ b/vendor/xflags/examples/hello-generated.rs
@@ -0,0 +1,52 @@
+mod flags {
+ #![allow(unused)]
+
+ xflags::xflags! {
+ src "./examples/hello-generated.rs"
+
+ /// Prints a greeting.
+ cmd hello
+ /// Whom to greet.
+ required name: String
+ {
+ /// Use non-ascii symbols in the output.
+ optional -e, --emoji
+ }
+ }
+
+ // generated start
+ // The following code is generated by `xflags` macro.
+ // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
+ #[derive(Debug)]
+ pub struct Hello {
+ pub name: String,
+
+ pub emoji: bool,
+ }
+
+ impl Hello {
+ pub const HELP: &'static str = Self::HELP_;
+
+ pub fn from_env() -> xflags::Result<Self> {
+ Self::from_env_()
+ }
+
+ pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
+ Self::from_vec_(args)
+ }
+ }
+ // generated end
+}
+
+fn main() {
+ match flags::Hello::from_env() {
+ Ok(flags) => {
+ let bang = if flags.emoji { "❣️" } else { "!" };
+ println!("Hello {}{}", flags.name, bang);
+ }
+ Err(err) => {
+ eprintln!("{}\n\n{}", err, flags::Hello::HELP);
+ std::process::exit(1)
+ }
+ }
+}
diff --git a/vendor/xflags/examples/hello.rs b/vendor/xflags/examples/hello.rs
new file mode 100644
index 000000000..98a19099f
--- /dev/null
+++ b/vendor/xflags/examples/hello.rs
@@ -0,0 +1,22 @@
+mod flags {
+ xflags::xflags! {
+ cmd hello
+ required name: String
+ {
+ optional -e, --emoji
+ }
+ }
+}
+
+fn main() {
+ match flags::Hello::from_env() {
+ Ok(flags) => {
+ let bang = if flags.emoji { "❣️" } else { "!" };
+ println!("Hello {}{}", flags.name, bang);
+ }
+ Err(err) => {
+ eprintln!("{}", err);
+ std::process::exit(1)
+ }
+ }
+}
diff --git a/vendor/xflags/examples/longer.rs b/vendor/xflags/examples/longer.rs
new file mode 100644
index 000000000..7ea9e18d5
--- /dev/null
+++ b/vendor/xflags/examples/longer.rs
@@ -0,0 +1,93 @@
+mod flags {
+ #![allow(unused)]
+
+ use std::path::PathBuf;
+
+ xflags::xflags! {
+ src "./examples/longer.rs"
+
+ cmd rust-analyzer {
+ /// Set verbosity level
+ repeated -v, --verbose
+ /// Log to the specified file instead of stderr.
+ optional --log-file path: PathBuf
+
+ default cmd run-server {
+ /// Print version
+ optional --version
+ }
+
+ /// Parse tree
+ cmd parse {
+ /// Suppress printing
+ optional --no-dump
+ }
+
+ /// Benchmark specific analysis operation
+ cmd analysis-bench
+ /// Directory with Cargo.toml
+ optional path: PathBuf
+ {
+ /// Compute syntax highlighting for this file
+ required --highlight path: PathBuf
+ /// Compute highlighting for this line
+ optional --line num: u32
+ }
+ }
+ }
+
+ // generated start
+ // The following code is generated by `xflags` macro.
+ // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
+ #[derive(Debug)]
+ pub struct RustAnalyzer {
+ pub verbose: u32,
+ pub log_file: Option<PathBuf>,
+ pub subcommand: RustAnalyzerCmd,
+ }
+
+ #[derive(Debug)]
+ pub enum RustAnalyzerCmd {
+ RunServer(RunServer),
+ Parse(Parse),
+ AnalysisBench(AnalysisBench),
+ }
+
+ #[derive(Debug)]
+ pub struct RunServer {
+ pub version: bool,
+ }
+
+ #[derive(Debug)]
+ pub struct Parse {
+ pub no_dump: bool,
+ }
+
+ #[derive(Debug)]
+ pub struct AnalysisBench {
+ pub path: Option<PathBuf>,
+
+ pub highlight: PathBuf,
+ pub line: Option<u32>,
+ }
+
+ impl RustAnalyzer {
+ pub const HELP: &'static str = Self::HELP_;
+
+ pub fn from_env() -> xflags::Result<Self> {
+ Self::from_env_()
+ }
+
+ pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
+ Self::from_vec_(args)
+ }
+ }
+ // generated end
+}
+
+fn main() {
+ match flags::RustAnalyzer::from_env() {
+ Ok(flags) => eprintln!("{:#?}", flags),
+ Err(err) => eprintln!("{}", err),
+ }
+}
diff --git a/vendor/xflags/examples/non-utf8.rs b/vendor/xflags/examples/non-utf8.rs
new file mode 100644
index 000000000..d355b24f6
--- /dev/null
+++ b/vendor/xflags/examples/non-utf8.rs
@@ -0,0 +1,43 @@
+use std::ffi::OsString;
+
+mod flags {
+ use std::{ffi::OsString, path::PathBuf};
+
+ xflags::xflags! {
+ cmd Cmd
+ required a: OsString
+ required b: PathBuf
+ required c: String
+ {
+ }
+ }
+}
+
+#[cfg(unix)]
+fn main() {
+ use std::os::unix::ffi::OsStringExt;
+
+ let flags = flags::Cmd::from_vec(vec![
+ OsString::from_vec(vec![254].into()),
+ OsString::from_vec(vec![255].into()),
+ "utf8".into(),
+ ]);
+
+ eprintln!("flags = {:?}", flags);
+}
+
+#[cfg(windows)]
+fn main() {
+ use std::os::windows::ffi::OsStringExt;
+
+ let flags = flags::Cmd::from_vec(vec![
+ OsString::from_wide(&[0xD800]),
+ OsString::from_wide(&[0xDC00]),
+ "utf8".into(),
+ ]);
+
+ eprintln!("flags = {:?}", flags);
+}
+
+#[cfg(not(any(unix, windows)))]
+fn main() {}