From 1e63070b73b6950eb4f798f20176a94bff73349d Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 27 Aug 2020 18:02:02 +0530 Subject: Add help option, update documentation to explain new profiles --- README | 54 +++++++++++------------------------------------------- leo.pl | 7 ++++--- 2 files changed, 15 insertions(+), 46 deletions(-) diff --git a/README b/README index 2f52d71..cb1f1fd 100644 --- a/README +++ b/README @@ -9,7 +9,7 @@ Table of Contents ───────────────── 1 Documentation -.. 1.1 Dispatch table +.. 1.1 Profile .. 1.2 Options ..... 1.2.1 encrypt/sign ..... 1.2.2 delete @@ -33,51 +33,19 @@ list. It can encrypt/sign files with gpg2(1). computer as a backup. -1.1 Dispatch table -────────────────── - - `%dispatch' has the pre-defined list. Learn the list directly from - `leo.pl', it's self-explanatory. Or check the sub `HelpMessage', it - explains what each command does. - - For example, `documents' will archive `$ENV{HOME}/documents' to - `/tmp/archive/documents_$ymd.tar' where `$ymd' is current date in - `YYYY-MM-DD' format. - ┌──── - │ my %dispatch = ( - │ journal => sub { - │ archive("$archive_dir/journal_$ymd.tar", - │ "-C", "$ENV{HOME}/documents", - │ "andinus.org.gpg", "archive.org.gpg"); - │ }, - │ ... - │ ); - └──── - - Currently I generate the dispatch table with a function & only special - profiles are added manually like above. `journal' is a special profile - because I don't want encryption on it. +1.1 Profile +─────────── - Other profiles are added by this function: - ┌──── - │ # This adds the directories that have same path relative to $ENV{HOME} - │ # as profile name. - │ foreach my $profile (qw( emails music projects documents .ssh - │ .password-store)) { - │ $dispatch{$profile} = sub { - │ archive("$archive_dir/${profile}_$ymd.tar", - │ "-C", "$ENV{HOME}/$profile", "."); - │ }; - │ } - └──── + Profile is a simple hash table which contains the list of profiles. + The profiles are mapped to a list of file paths relative to `$HOME' + which are to be archived. - I alias paths like `.ssh' to make it convenient to type: + Complex profiles are hard coded & simple ones are generated. Complex + profiles include profiles that have multiple files or are a mix or + files & directories. Simple profiles are profiles with just single + directory. - ┌──── - │ # Aliases for inconvenient paths. - │ $dispatch{ssh} = $dispatch{".ssh"}; - │ $dispatch{pass} = $dispatch{".password-store"}; - └──── + You can run `help' to see all the profiles along with the paths. 1.2 Options diff --git a/leo.pl b/leo.pl index 1222963..cd6a297 100755 --- a/leo.pl +++ b/leo.pl @@ -11,7 +11,7 @@ use Getopt::Long qw/ GetOptions /; my %options = (); GetOptions( \%options, - qw{ verbose encrypt sign delete } + qw{ verbose encrypt sign delete help } ) or die "Error in command line arguments\n"; $options{encrypt} = $ENV{LEO_ENCRYPT}; @@ -45,7 +45,7 @@ $profile{ssh} = $profile{".ssh"}; $profile{pass} = $profile{".password-store"}; $profile{mozilla} = $profile{".mozilla"}; -HelpMessage() and exit 0 if scalar @ARGV == 0; +HelpMessage() and exit 0 if scalar @ARGV == 0 or $options{help}; foreach my $arg ( @ARGV ) { $prof = $arg; # Set $prof. if ( $profile{ $arg } ) { @@ -129,7 +129,8 @@ Options: Sign files with $gpg_fingerprint --delete Delete the archive after running gpg2 - --verbose}; + --verbose + --help}; } -- cgit 1.4.1-2-gfad0