1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* graftfs
* Copyright (C) 2026 Chris Tisdale
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//!
//! # Graft
//!
//! A Rust implementation of the GNU stow utility for managing dotfiles. It is a symlink farm manager that takes separate packages of software and/or data and makes them appear to be installed in the same place. Features include stow, delete, and restow operations, simulation mode, directory folding, and regex-based ignore/override patterns.
//!
//! # Usage
//!
//! graft \[OPTIONS\] \<COMMAND\>
//!
//! # Commands
//!
//! - stow: Create symlinks for the specified package(s).
//! - delete: Remove symlinks for the specified package(s).
//! - restow: Restow the specified package(s) by first deleting and then stowing
//! - list: List all available packages and their stow status.
//!
//! # Features
//!
//! - Simulation mode: Use the `--simulate` flag to see what actions would be taken without making any changes to the filesystem.
//! - Directory folding: Automatically fold directories when stowing to avoid creating unnecessary intermediate directories.
//! - Ignore/Override patterns: Use regex-based patterns to specify files or directories to ignore or override during stow operations.
//! - Configuration file support: Define default options and package configurations in a configuration file
//! - Cross-platform compatibility: Works on Unix-like systems (Linux, macOS) and Windows.
//! - Detailed logging: Provides detailed logs of stow operations, including actions taken and any errors encountered.
//!
//! # Configuration File
//!
//! `graft` can be configured using a `.graft.toml` file. It looks for this file in the current working directory or in the user's configuration directory. The file is in TOML format.
//!
//! Example `.graft.toml`:
//!
//! ```toml
//! version = 1
//!
//! [ignored]
//! file = ".graft-ignore"
//! comment = '#'
//!
//! [overrides]
//! file = ".graft-override"
//! comment = '#'
//!
//! [logging]
//! level = "Info"
//! logging_path = "path/to/logs"
//! rotation = "Daily"
//! max_log_files = 30
//! color_support = true
//! ```
//!
//! ## Version 1 Configuration Options
//!
//! ### Ignored Files
//!
//! - `file`: The name of the file that contains the list of files or directories to ignore during stow operations. Each line in this file represents a pattern to ignore. Lines starting with the `comment` character are treated as comments and ignored.
//! - `comment`: The character used to denote comments in the ignore file. Lines starting with this character are ignored when processing the ignore patterns.
//!
//! ### Override Files
//!
//! - `file`: The name of the file that contains the list of files or directories to override during stow operations. Each line in this file represents a pattern to override. Lines starting with the `comment` character are treated as comments and ignored.
//! - `comment`: The character used to denote comments in the override file. Lines starting with this character are ignored when processing the override patterns.
//!
//! ### Logging
//!
//! - `level`: The logging level for the application. Possible values include "Trace", "Debug", "Info", "Warn", and "Error". This setting determines the verbosity of the logs generated by the application.
//! - `logging_path`: The directory path where log files will be stored.
//! - `rotation`: The log rotation strategy. Possible values include "Daily" (rotate logs daily) and "Hourly" (rotate logs hourly). This setting determines how often log files are rotated to prevent them from growing indefinitely.
//! - `max_log_files`: The maximum number of log files to retain. When the number of log files exceeds this limit, the oldest log files will be deleted to free up space.
//! - `color_support`: A boolean flag indicating whether to enable color support in log output. If set to `true`, log messages will be color-coded based on their severity level (e.g., errors in red, warnings in yellow). If set to `false`, log messages will be displayed without color coding.
//!
//! ## Configuration Location
//!
//! ### `MacOS`
//!
//! On `MacOS`, the configuration files will be located in the following locations:
//!
//! - If `XDG_CONFIG_HOME` is set, `$XDG_CONFIG_HOME/graft/.graft.toml`
//! - If `XDG_CONFIG_HOME` is not set, `~/Library/Preferences/graft/.graft.toml`
//!
//! ### Linux
//!
//! On Linux, the configuration files will be located in the following locations:
//!
//! - If `XDG_CONFIG_HOME` is set, `$XDG_CONFIG_HOME/graft/.graft.toml`
//! - If `XDG_CONFIG_HOME` is not set, `~/.config/graft/`.
//!
//! ### Windows
//!
//! On Windows, the configuration files will be located in the following location:
//!
//! -`%APPDATA%\graft\.graft.toml`
//!
//! # Examples
//!
//! Stow a package:
//!
//! ```bash
//! graft stow -d my_package
//! ```
//!
//! Delete a package:
//!
//! ```bash
//! graft delete -d my_package
//! ```
//!
//! Restow a package:
//!
//! ```bash
//! graft restow -d my_package
//! ```
//!
//! List all packages and their stow status:
//!
//! ```bash
//! graft list -d my_package
//! ```
//!
use crateCliError;
use crateCommandLineProcessor;
use ;