MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / parse_args

Function parse_args

src/bin/pglite_proxy.rs:68–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67
68fn parse_args() -> Result<Args> {
69 let mut root = None;
70 let mut temporary = false;
71 let mut print_uri = false;
72 let mut postgres_config = Vec::new();
73 let mut extensions = Vec::new();
74 let mut bind = Bind::Tcp("127.0.0.1:5432".parse().expect("valid default TCP addr"));
75
76 let mut args = env::args().skip(1);
77 while let Some(arg) = args.next() {
78 match arg.as_str() {
79 "--temporary" => temporary = true,
80 "--root" => {
81 let value = args
82 .next()
83 .ok_or_else(|| anyhow::anyhow!("--root requires a path"))?;
84 root = Some(PathBuf::from(value));
85 temporary = false;
86 }
87 "--tcp" => {
88 let value = args.next().unwrap_or_else(|| "127.0.0.1:5432".to_string());
89 bind = Bind::Tcp(
90 value
91 .parse()
92 .with_context(|| format!("parse TCP bind address {value}"))?,
93 );
94 }
95 #[cfg(unix)]
96 "--unix" | "--uds" => {
97 let value = args
98 .next()
99 .unwrap_or_else(|| "/tmp/.s.PGSQL.5432".to_string());
100 bind = Bind::Unix(PathBuf::from(value));
101 }
102 "--print-uri" => print_uri = true,
103 "--postgres-config" => {
104 let value = args
105 .next()
106 .ok_or_else(|| anyhow::anyhow!("--postgres-config requires name=value"))?;
107 let (name, value) = value
108 .split_once('=')
109 .ok_or_else(|| anyhow::anyhow!("--postgres-config requires name=value"))?;
110 postgres_config.push((name.to_owned(), value.to_owned()));
111 }
112 "--extension" => {
113 let value = args
114 .next()
115 .ok_or_else(|| anyhow::anyhow!("--extension requires a name"))?;
116 extensions.push(value);
117 }
118 "--help" | "-h" => {
119 print_usage();
120 std::process::exit(0);
121 }
122 other => bail!("unknown argument: {other}"),
123 }
124 }
125

Callers 1

mainFunction · 0.70

Calls 3

pushMethod · 0.80
print_usageFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected