permcon/lib.rs
1//! A simple library/CLI to parse Linux file permissions and convert them between symbolic
2//! and octal notation.
3//!
4//! ## Library Usages
5//!
6//! ```rust
7//! use permcon::{FilePermission, GroupPermission, SourceFormat, SpecialPermission};
8//! use permcon::utils::get_filetype_from_char;
9//!
10//! let perm = FilePermission::try_from("-rwxr-xr-T").unwrap();
11//!
12//! assert_eq!(perm, FilePermission {
13//! user: GroupPermission {
14//! read: true,
15//! write: true,
16//! execute: true,
17//! special: false,
18//! },
19//! group: GroupPermission {
20//! read: true,
21//! write: false,
22//! execute: true,
23//! special: false,
24//! },
25//! other: GroupPermission {
26//! read: true,
27//! write: false,
28//! execute: false,
29//! special: true,
30//! },
31//! filetype_char: '-',
32//! filetype: get_filetype_from_char('-'),
33//! source_format: Some(SourceFormat::Symbolic),
34//! special: [SpecialPermission::Nil, SpecialPermission::Nil, SpecialPermission::StickyBit],
35//! });
36//! ```
37//! <br>
38//!
39//! ## CLI usages
40//!
41//! ```bash,ignore
42//! ❯ permcon 1754
43//! # -rwxr-xr-T
44//!
45//! ❯ permcon -- rwxrwxr-t
46//! # 1775
47//!
48//! # Note: a `--` is required if the permission string starts with an `-`.
49//! ❯ permcon -- -rwxrwxr-t
50//! # 1775
51//!
52//! ❯ permcon -a -- -rwxrwxr-t
53//! # file type : Regular File
54//! # symbolic : -rwxrwxr-t
55//! # octal : 1775
56//! # ------------------------
57//! # user (rwx, 7): read, write, execute
58//! # group(rwx, 7): read, write, execute
59//! # other(r-t, 5): read, _ , (execute, StickyBit)
60//! # ------------------------
61//! # special permissions: StickyBit
62//!
63//! ❯ permcon -a 1754
64//! # file type : Unknown
65//! # symbolic : -rwxr-xr-T
66//! # octal : 1754
67//! # ------------------------
68//! # user (rwx, 7): read, write, execute
69//! # group(r-x, 5): read, _ , execute
70//! # other(r-T, 4): read, _ , (_, StickyBit)
71//! # ------------------------
72//! # special permissions: StickyBit
73//! ```
74
75pub mod octal;
76pub mod perm;
77pub mod symbolic;
78pub mod utils;
79pub use octal::Octal;
80pub use perm::{FilePermission, GroupPermission, SourceFormat, SpecialPermission};
81pub use symbolic::Symbolic;