gpio_utils/commands/
gpio_unexport.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 crate::config::GpioConfig;
10use crate::export;
11use crate::options::GpioUnexportOptions;
12use std::process::exit;
13
14pub fn main(config: &GpioConfig, opts: &GpioUnexportOptions) {
15    let pin_config = config.get_pin(opts.pin).unwrap_or_else(|| {
16        println!("Unable to find config entry for pin '{}'", opts.pin);
17        exit(1)
18    });
19
20    let symlink_root = match opts.symlink_root {
21        Some(slr) => slr,
22        None => config.get_symlink_root(),
23    };
24
25    if let Err(e) = export::unexport(pin_config, Some(symlink_root)) {
26        println!("Error occurred while unexport pin {:?}", pin_config);
27        println!("{}", e);
28        exit(1);
29    }
30}