2022-09-25 01:24:31 +00:00
/*
* Vento , a CLI inventory for your files .
* Copyright ( C ) 2022 Lux Aliaga
*
* 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 < https ://www.gnu.org/licenses/>.
*
* /
use anyhow ::Result ;
use man ::prelude ::* ;
use std ::env ;
use std ::fs ::{ create_dir_all , File } ;
use std ::io ::Write ;
2022-10-17 23:09:44 +00:00
struct Page {
content : String ,
file : String ,
}
2022-09-25 01:24:31 +00:00
fn main ( ) -> Result < ( ) > {
if cfg! ( unix ) {
2022-09-27 02:58:42 +00:00
let pages = [ vento ( ) ? , take ( ) ? , drop ( ) ? , ventotoml ( ) ? ] ;
2022-09-25 01:24:31 +00:00
let tempdir = env ::temp_dir ( ) . join ( " vento-man " ) ;
create_dir_all ( tempdir . clone ( ) ) ? ;
2022-10-01 20:38:14 +00:00
for page in & pages {
2022-10-17 23:09:44 +00:00
let tempfile = tempdir . join ( & page . file ) ;
2022-09-25 01:24:31 +00:00
let mut file = File ::create ( tempfile ) . unwrap ( ) ;
2022-10-17 23:09:44 +00:00
write! ( & mut file , " {} " , & page . content ) . unwrap ( ) ;
2022-09-25 01:24:31 +00:00
}
}
Ok ( ( ) )
}
2022-10-17 23:09:44 +00:00
fn vento ( ) -> Result < Page > {
let content = Manual ::new ( " vento " )
2022-09-25 01:24:31 +00:00
. about ( " a CLI inventory for your files " )
2023-08-28 05:55:17 +00:00
. author ( Author ::new ( " Lux Aliaga " ) . email ( " lux@nixgoat.me " ) )
2022-09-25 01:24:31 +00:00
. description ( " List files and directories in the currently active inventory, the files in SLOT, the files in DIRECTORY or the files in DIRECTORY in SLOT. " )
. flag (
Flag ::new ( )
2022-09-26 19:54:39 +00:00
. short ( " -c " )
2022-09-25 01:24:31 +00:00
. long ( " --switch " )
. help ( " Switches inventory slots " ) ,
)
2022-10-26 20:02:23 +00:00
. flag (
Flag ::new ( )
. short ( " -u " )
. long ( " --undo " )
. help ( " Undoes the last action " ) ,
)
2023-02-19 16:28:19 +00:00
. flag (
Flag ::new ( )
. short ( " -e " )
. long ( " --export-inv " )
. help ( " Exports an inventory " ) ,
)
. flag (
Flag ::new ( )
. short ( " -E " )
. long ( " --export-dir " )
. help ( " Exports the Vento directory " ) ,
)
. flag (
Flag ::new ( )
. short ( " -g " )
. long ( " --import-inv " )
. help ( " Imports an inventory archive " ) ,
)
. flag (
Flag ::new ( )
. short ( " -G " )
. long ( " --import-dir " )
. help ( " Imports a Vento directory archive " ) ,
)
2022-09-25 01:24:31 +00:00
. flag (
Flag ::new ( )
. short ( " -i " )
. long ( " --init " )
. help ( " Initializes Vento with all its respective directories " ) ,
)
. flag (
Flag ::new ( )
. short ( " -h " )
. long ( " --help " )
. help ( " Shows the help message " ) ,
)
2022-09-26 19:54:39 +00:00
. option (
Opt ::new ( " slot " )
. short ( " -s " )
. long ( " --slot " )
. help ( " The slot to list " ) ,
)
2022-09-25 01:24:31 +00:00
. arg ( Arg ::new ( " [DIRECTORY] " ) )
. custom (
Section ::new ( " before starting " )
. paragraph ( " Vento will first need to initialize the respective directories before usage. Do this by running vento -i. " )
)
. render ( ) ;
2022-10-17 23:09:44 +00:00
Ok ( Page {
content ,
file : String ::from ( " vento.1 " ) ,
} )
2022-09-25 01:24:31 +00:00
}
2022-10-17 23:09:44 +00:00
fn take ( ) -> Result < Page > {
let content = Manual ::new ( " take " )
2022-09-25 01:24:31 +00:00
. about ( " a file grabber for Vento " )
2023-08-28 05:55:17 +00:00
. author ( Author ::new ( " Lux Aliaga " ) . email ( " lux@nixgoat.me " ) )
2022-09-25 01:24:31 +00:00
. description ( " Take FILE and put it in the inventory. " )
. option (
Opt ::new ( " slot " )
. short ( " -s " )
. long ( " --slot " )
. help ( " The slot to put the file in " ) ,
)
. arg ( Arg ::new ( " FILE " ) )
. render ( ) ;
2022-10-17 23:09:44 +00:00
Ok ( Page {
content ,
file : String ::from ( " take.1 " ) ,
} )
2022-09-25 01:24:31 +00:00
}
2022-10-17 23:09:44 +00:00
fn drop ( ) -> Result < Page > {
let content = Manual ::new ( " drop " )
2022-09-25 01:24:31 +00:00
. about ( " a file dropper for Vento " )
2023-08-28 05:55:17 +00:00
. author ( Author ::new ( " Lux Aliaga " ) . email ( " lux@nixgoat.me " ) )
2022-09-25 01:24:31 +00:00
. description ( " Take FILE off the inventory and drop it in DESTINATION. " )
. option (
Opt ::new ( " slot " )
. short ( " -s " )
. long ( " --slot " )
. help ( " The slot to take the file from " ) ,
)
. arg ( Arg ::new ( " FILE " ) )
. arg ( Arg ::new ( " [DESTINATION] " ) )
. render ( ) ;
2022-10-17 23:09:44 +00:00
Ok ( Page {
content ,
file : String ::from ( " drop.1 " ) ,
} )
2022-09-25 01:24:31 +00:00
}
2022-09-27 02:58:42 +00:00
2022-10-17 23:09:44 +00:00
fn ventotoml ( ) -> Result < Page > {
let content = Manual ::new ( " vento.toml " )
2022-09-27 02:58:42 +00:00
. about ( " configuration file for Vento " )
2023-08-28 05:55:17 +00:00
. author ( Author ::new ( " Lux Aliaga " ) . email ( " lux@nixgoat.me " ) )
. description ( " This is the configuration file for the vento(1), take(1) and drop(1) utilities. Its presence and all its directives are optional. Directives prefixed with \" name.directive \" indicate a separate section in config file, denoted by brackets. " )
2022-09-27 02:58:42 +00:00
. custom (
Section ::new ( " supported directives " )
. paragraph ( " directory = \" PATH \" : Changes the path in which Vento's inventories are saved in. " )
2023-08-28 05:55:17 +00:00
. paragraph ( " display_emoji = (true | false): Sets whether emojis will be prefixed on messages or not. " )
. paragraph ( " display_colors = (true | false): Sets whether messages will be colored. " )
. paragraph ( " item.display_dir = (true | false): Sets whether item actions will show the paths involved in the operation. " )
. paragraph ( " history.display_dir = (true | false): Sets whether history actions will show the paths involved in the operation. " )
2022-09-27 02:58:42 +00:00
)
. custom (
Section ::new ( " files " )
. paragraph ( " Linux: $XDG_CONFIG_HOME/vento.toml " )
. paragraph ( " macOS: $HOME/Library/Application Support/vento.toml " )
2022-09-27 03:05:06 +00:00
. paragraph ( " Windows: {FOLDERID_RoamingAppData} \\ \\ vento.toml " )
2022-09-27 02:58:42 +00:00
)
. render ( ) ;
2022-10-17 23:09:44 +00:00
Ok ( Page {
content ,
file : String ::from ( " vento.toml.1 " ) ,
} )
2022-09-27 02:58:42 +00:00
}