gpio_utils/commands/
gpio_exportall.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::GpioExportAllOptions;
12use std::process::exit;
13
14pub fn main(config: &GpioConfig, opts: &GpioExportAllOptions) {
15    let symlink_root = match opts.symlink_root {
16        Some(slr) => slr,
17        None => config.get_symlink_root(),
18    };
19
20    // export all pins except those for which export is set to false
21    for pin in config.get_pins().iter().filter(|p| p.export) {
22        if let Err(e) = export::export(pin, Some(symlink_root)) {
23            println!("Error occurred while exporting pin: {:?}", pin);
24            println!("{}", e);
25            exit(1);
26        }
27    }
28}