Skip to content

Commit dcc53cd

Browse files
committed
Add some basic examples
1 parent df6e80d commit dcc53cd

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

core/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ tokio-core = "0.1"
3232
tokio-io = "0.1"
3333
tokio-proto = "0.1"
3434
tokio-service = "0.1"
35+
36+
[[example]]
37+
name = "basic"
38+
39+
[[example]]
40+
name = "remote_host"

core/examples/basic.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015-2017 Intecture Developers.
2+
//
3+
// Licensed under the Mozilla Public License 2.0 <LICENSE or
4+
// https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
5+
// modified, or distributed except according to those terms.
6+
7+
extern crate futures;
8+
extern crate intecture_api;
9+
extern crate tokio_core;
10+
11+
use futures::Future;
12+
use intecture_api::prelude::*;
13+
use tokio_core::reactor::Core;
14+
15+
fn main() {
16+
let mut core = Core::new().unwrap();
17+
18+
let host = Local::new().and_then(|host| {
19+
command::factory(&host, "whoami", None).and_then(|mut cmd| {
20+
cmd.exec().map(|out| {
21+
println!("I'm currently running as {}", String::from_utf8_lossy(&out.stdout).trim());
22+
})
23+
})
24+
});
25+
26+
core.run(host).unwrap();
27+
}

core/examples/remote_host.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015-2017 Intecture Developers.
2+
//
3+
// Licensed under the Mozilla Public License 2.0 <LICENSE or
4+
// https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
5+
// modified, or distributed except according to those terms.
6+
7+
extern crate futures;
8+
extern crate intecture_api;
9+
extern crate tokio_core;
10+
11+
use futures::Future;
12+
use intecture_api::prelude::*;
13+
use tokio_core::reactor::Core;
14+
15+
fn main() {
16+
let mut core = Core::new().unwrap();
17+
let handle = core.handle();
18+
19+
let host = Plain::connect("127.0.0.1:7101", &handle).map(|host| {
20+
println!("Connected to {}", host.telemetry().hostname);
21+
});
22+
23+
core.run(host).unwrap();
24+
}

0 commit comments

Comments
 (0)