| 1 | package StandupGenerator::Manipulator; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | our @EXPORT = qw( | |||||||||
| 6 | save_script_shortcuts | ||||||||||
| 7 | ); | ||||||||||
| 8 | |||||||||||
| 9 | # Updates a user's local zsh or bash config file with functions allowing the user to implement methods from the package via the CLI using far less typing | ||||||||||
| 10 | 0 | ▶ | sub save_script_shortcuts { | ||||||||
|
Subroutine
save_script_shortcuts: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 11 | 0 | my ($path) = @_; | |||||||||
| 12 | 0 | my @sections = split('/', $path); | |||||||||
| 13 | 0 | my $user = $sections[2]; | |||||||||
| 14 | 0 | my $base = "/Users/${user}"; | |||||||||
| 15 | 0 | my $config; | |||||||||
| 16 | 0 | my $zsh = "${base}/.zshrc"; | |||||||||
| 17 | 0 | my $bash = "${base}/.bashrc"; | |||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | if (-e $zsh) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | # Plan to update user's zsh file if it exists | ||||||||||
| 21 | 0 | $config = $zsh; | |||||||||
| 22 | } else { | ||||||||||
| 23 | # Plan to update user's bash file if user does not use zsh | ||||||||||
| 24 | 0 | $config = $bash; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | open my $fh, '<', $config; | |||||||||
| 28 | 0 | my $config_content = do { local $/; <$fh> }; | |||||||||
| 29 | 0 | close($fh); | |||||||||
| 30 | |||||||||||
| 31 | # Create three functions for creating and opening standup files, then bundle them together into a single string for group insertion | ||||||||||
| 32 | 0 | my $osu = "# Executes open_standup function from standup-generator Perl module\n# Takes three arguments: path to directory housing standups, sprint number, and string of day beginning with 0 (e.g., '04', not 4)\nfunction osu() {\n\tsprint=\$1\n\tday=\$2\n\texport sprint\n\texport day\n\tperl -e 'use StandupGenerator; open_standup(\"${path}\", \$ENV{sprint}, \$ENV{day})'\n}"; | |||||||||
| 33 | 0 | my $csu = "# Executes create_standup function from standup-generator Perl module; it takes no arguments\nfunction csu() {\n\tperl -e 'use StandupGenerator; create_standup(\"${path}\")'\n}"; | |||||||||
| 34 | 0 | my $wsu = "# Executes view_standups_from_week function from standup-generator Perl module; it takes no arguments\nfunction wsu() {\n\tperl -e 'use StandupGenerator; view_standups_from_week(\"${path}\")'\n}"; | |||||||||
| 35 | 0 | my $updated_content = "${config_content}\n\n${osu}\n\n${csu}\n\n${wsu}"; | |||||||||
| 36 | |||||||||||
| 37 | # Append new shortcuts to the end of existing config file | ||||||||||
| 38 | 0 | open my $new_fh, '>', $config; | |||||||||
| 39 | 0 | print $new_fh $updated_content; | |||||||||
| 40 | 0 | close($new_fh); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 3 | 1; | |||||||||
| 44 | |||||||||||
| 45 | __END__ | ||||||||||