owdir/
owdir.rs

1//! **owdir** -- _Rust version_
2//!
3//! ## Read a directory from owserver
4//!
5//! **owdir** a tool in the 1-wire file system **OWFS**
6//!
7//! This Rust version of **owdir** is part of **owrust** -- the _Rust language_ OWFS programs
8//! * **OWFS** [documentation](https://owfs.org) and [code](https://github.com/owfs/owfs)
9//! * **owrust** [repository](https://github.com/alfille/owrust)
10//!
11//! ## SYNTAX
12//! ```
13//! owdir [OPTIONS] PATH
14//! ```
15//! ## PURPOSE
16//! __owdir__ shows a 1-wire "directory" via owserver
17//! * Root (/) directories show devices and informational entries (like `statistics`)
18//! * Device (/10.132542312) directories show device entries. Information and properties (like `temperature`)
19//! * All entries are shown from the root of owserver. There is no "current directory"
20//!
21//! ## OPTIONS
22//! * `-s IP:port` (default `localhost:4304`)
23//! * `--dir`      Add trailing **/** for directory elements
24//! * `--bare`     Suppress non-device entries
25//! * `--prune`    Even more spare output suppressing convenience files like `id` and `crc`
26//! * -h           for full list of options
27//!
28//! ## PATH
29//! * 1-wire path
30//! * default is root **/**
31//! * more than one path can be given
32//!
33//! ## USAGE
34//! * owserver must be running in a network-accessible location
35//! * `owdir` is a command line program
36//! * output to stdout
37//! * errors to stderr
38//!
39//! ## EXAMPLE
40//! Read root 1-wire directory
41//! ```
42//! owdir -s localhost:4304 /
43//! ```
44//! ```text
45//! /10.67C6697351FF
46//! /05.4AEC29CDBAAB
47//! /bus.0
48//! /uncached
49//! /settings
50//! /system
51//! /statistics
52//! /structure
53//! /simultaneous
54//! /alarm
55//! ```
56//! Read the root directory, but dont'show non-devices
57//! ```
58//! owdir -s localhost:4304 --bare /
59//! ```
60//! ```text
61//! /10.67C6697351FF
62//! /05.4AEC29CDBAAB
63//! ```
64//! Read a device directory
65//! ```
66//! owdir -s localhost:4304 /10.67C6697351FF
67//! ```
68//! ```text
69//! /10.67C6697351FF/address
70//! /10.67C6697351FF/alias
71//! /10.67C6697351FF/crc8
72//! /10.67C6697351FF/errata
73//! /10.67C6697351FF/family
74//! /10.67C6697351FF/id
75//! /10.67C6697351FF/latesttemp
76//! /10.67C6697351FF/locator
77//! /10.67C6697351FF/power
78//! /10.67C6697351FF/r_address
79//! /10.67C6697351FF/r_id
80//! /10.67C6697351FF/r_locator
81//! /10.67C6697351FF/scratchpad
82//! /10.67C6697351FF/temperature
83//! /10.67C6697351FF/temphigh
84//! /10.67C6697351FF/templow
85//! /10.67C6697351FF/type
86//! ```
87//! Read a device directory "pruning out" the convenience entries
88//! ```
89//! owdir -s localhost:4304 --prune /10.67C6697351FF
90//! ```
91//! ```text
92//! /10.67C6697351FF/alias
93//! /10.67C6697351FF/errata
94//! /10.67C6697351FF/latesttemp
95//! /10.67C6697351FF/power
96//! /10.67C6697351FF/scratchpad
97//! /10.67C6697351FF/temperature
98//! /10.67C6697351FF/temphigh
99//! /10.67C6697351FF/templow
100//! ```
101//! ### {c} 2025 Paul H Alfille -- MIT Licence
102
103// owrust project
104// https://github.com/alfille/owrust
105//
106// This is a Rust version of my C owfs code for talking to 1-wire devices via owserver
107// Basically owserver can talk to the physical devices, and provides network access via my "owserver protocol"
108
109use owrust::console::console_lines;
110use owrust::parse_args::{OwDir, Parser};
111
112fn main() {
113    let mut owserver = owrust::new(); // create structure for owserver communication
114    let prog = OwDir;
115
116    // configure and get paths
117    match prog.command_line(&mut owserver) {
118        Ok(paths) => {
119            if paths.is_empty() {
120                // No path -- assume root
121                from_path(&mut owserver, "/".to_string());
122            } else {
123                // for each path in command line
124                for path in paths.into_iter() {
125                    from_path(&mut owserver, path);
126                }
127            }
128        }
129        Err(e) => {
130            eprintln!("owdir trouble {}", e);
131        }
132    }
133}
134
135// print 1-wire directory contents
136fn from_path(owserver: &mut owrust::OwMessage, path: String) {
137    match owserver.dirall(&path) {
138        Ok(files) => console_lines(files),
139        Err(e) => eprintln!("Trouble with path {} Error {}", path, e),
140    }
141}