Skip to content

Commit

Permalink
Merged PR 881186: Add host option to iotedge
Browse files Browse the repository at this point in the history
* This adds an option to set the management uri. (-H, env var IOTEDGE_HOST)
* Removes the `TYPE` column from the list command

```
iotedge 0.1.0
Azure IoT Edge Devs <[email protected]>

USAGE:
    iotedge [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -H, --host <HOST>    Daemon socket to connect to [env: IOTEDGE_HOST=]  [default: unix:///var/run/iotedge/mgmt.sock]

SUBCOMMANDS:
    help       Prints this message or the help of the given subcommand(s)
    list       List modules
    logs       Fetch the logs of a module
    restart    Restart a module
    start      Start a module
    stop       Stop a module
    version    Show the version information

```
  • Loading branch information
myagley committed Jun 6, 2018
1 parent 8bcecf7 commit aa378ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions edgelet/iotedge/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum ErrorKind {
UrlParse,
#[fail(display = "An error in the management http client occurred.")]
HttpMgmt,
#[fail(display = "Missing host")]
NoHost,
}

impl Fail for Error {
Expand Down
5 changes: 2 additions & 3 deletions edgelet/iotedge/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ where
.map_err(|e| e.into())
.and_then(move |states| {
let mut w = write.borrow_mut();
writeln!(w, "NAME\tTYPE\tSTATUS\tDESCRIPTION\tCONFIG")?;
writeln!(w, "NAME\tSTATUS\tDESCRIPTION\tCONFIG")?;
for (module, state) in modules.iter().zip(states) {
writeln!(
w,
"{}\t{}\t{}\t{}\t{}",
"{}\t{}\t{}\t{}",
module.name(),
module.type_(),
state.status(),
humanize_state(&state),
module.config(),
Expand Down
19 changes: 17 additions & 2 deletions edgelet/iotedge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ fn main() {

fn run() -> Result<(), Error> {
let mut core = Core::new()?;
let url = Url::parse(MGMT_URI)?;
let runtime = ModuleClient::new(&url, &core.handle())?;

let matches = App::new(crate_name!())
.version(crate_version!())
.author(crate_authors!("\n"))
.about(crate_description!())
.setting(AppSettings::SubcommandRequiredElseHelp)
.arg(
Arg::with_name("host")
.help("Daemon socket to connect to")
.short("H")
.long("host")
.takes_value(true)
.value_name("HOST")
.global(true)
.env("IOTEDGE_HOST")
.default_value(MGMT_URI),
)
.subcommand(SubCommand::with_name("list").about("List modules"))
.subcommand(
SubCommand::with_name("start").about("Start a module").arg(
Expand Down Expand Up @@ -108,6 +117,12 @@ fn run() -> Result<(), Error> {
.subcommand(SubCommand::with_name("version").about("Show the version information"))
.get_matches();

let url = matches
.value_of("host")
.map(|h| Url::parse(h).map_err(Error::from))
.unwrap_or_else(|| Err(Error::from(ErrorKind::NoHost)))?;
let runtime = ModuleClient::new(&url, &core.handle())?;

match matches.subcommand() {
("list", Some(_args)) => core.run(List::new(runtime, io::stdout()).execute()),
("start", Some(args)) => core.run(
Expand Down

0 comments on commit aa378ec

Please sign in to comment.