Skip to content

Commit

Permalink
Add username and password args (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbangelo authored Jul 9, 2022
1 parent 7be4334 commit e471ceb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,35 @@ The `ntripping` utility has the following usage:
NTRIP command line client.

USAGE:
ntripping [FLAGS] [OPTIONS]

FLAGS:
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose
ntripping [OPTIONS]

OPTIONS:
--client-id <client-id> [default: 00000000-0000-0000-0000-000000000000]
--epoch <epoch>
--height <height> [default: -5.549358852471994]
--lat <lat> [default: 37.77101999622968]
--lon <lon> [default: -122.40315159140708]
--url <url> [default: na.skylark.swiftnav.com:2101/CRS]
--client <CLIENT> Client ID [default: 00000000-0000-0000-0000-000000000000]
--epoch <EPOCH> Receiver time to report, as a Unix time
-h, --help Print help information
--height <HEIGHT> Receiver height to report, in meters [default: -5.549358852471994]
--lat <LAT> Receiver latitude to report, in degrees [default:
37.77101999622968]
--lon <LON> Receiver longitude to report, in degrees [default:
-122.40315159140708]
--password <PASSWORD> Password credentials
--url <URL> URL of the NTRIP caster [default: na.skylark.swiftnav.com:2101/CRS]
--username <USERNAME> Username credentials
-v, --verbose
-V, --version Print version information

Different resources can be requested from different locations. By default, a San
Francisco latitude, longitude, and height will be used.

### Credentials

Access credentials are usually required to access NTRIP streams. These credentials can be
specified individually as command line arguments or directly in the URL like this

```
ntripping --url user:[email protected]:2101/CRS
```

## Copyright

```
Expand Down
22 changes: 22 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,44 @@ use curl::easy::{Easy, HttpVersion, List, ReadError};
#[derive(Debug, Parser)]
#[clap(name = "ntripping", about = "NTRIP command line client.", version = env!("VERGEN_SEMVER_LIGHTWEIGHT"))]
struct Cli {
/// URL of the NTRIP caster
#[clap(long, default_value = "na.skylark.swiftnav.com:2101/CRS")]
url: String,

/// Receiver latitude to report, in degrees
#[clap(long, default_value = "37.77101999622968", allow_hyphen_values = true)]
lat: String,

/// Receiver longitude to report, in degrees
#[clap(
long,
default_value = "-122.40315159140708",
allow_hyphen_values = true
)]
lon: String,

/// Receiver height to report, in meters
#[clap(long, default_value = "-5.549358852471994", allow_hyphen_values = true)]
height: String,

/// Client ID
#[clap(long, default_value = "00000000-0000-0000-0000-000000000000")]
client: String,

#[clap(short, long)]
verbose: bool,

/// Receiver time to report, as a Unix time
#[clap(long)]
epoch: Option<u32>,

/// Username credentials
#[clap(long)]
username: Option<String>,

/// Password credentials
#[clap(long)]
password: Option<String>,
}

type Result<T> = std::result::Result<T, Box<dyn Error>>;
Expand Down Expand Up @@ -96,6 +110,14 @@ fn main() -> Result<()> {
curl.verbose(true)?;
}

if let Some(username) = &opt.username {
curl.username(username)?;
}

if let Some(password) = &opt.password {
curl.password(password)?;
}

curl.write_function(|buf| Ok(io::stdout().write_all(buf).map_or(0, |_| buf.len())))?;

curl.progress_function(|_dltot, _dlnow, _ultot, _ulnow| {
Expand Down

0 comments on commit e471ceb

Please sign in to comment.