gpio_utils/commands/
gpio_export.rs

1// Copyright (c) 2016, The gpio-utils Authors.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/license/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option.  This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use config::GpioConfig;
10use export;
11use options::GpioExportOptions;
12use std::process::exit;
13
14pub fn main(config: &GpioConfig, opts: &GpioExportOptions) {
15    let pin = match config.get_pin(opts.pin) {
16        Some(pin) => pin,
17        None => {
18            println!("Unable to find config entry for pin '{}'", opts.pin);
19            exit(1)
20        }
21    };
22
23    let symlink_root = match opts.symlink_root {
24        Some(slr) => slr,
25        None => config.get_symlink_root(),
26    };
27
28    if let Err(e) = export::export(pin, Some(symlink_root)) {
29        println!("Error occurred while exporting pin: {:?}", pin);
30        println!("{}", e);
31        exit(1);
32    }
33}