-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxacman.pl
executable file
·107 lines (83 loc) · 2.33 KB
/
xacman.pl
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
#!/usr/bin/perl
# todo
# I want all failures to print a command list, not the xbps default
use v5.10.0;
use warnings;
use strict;
use feature qw(switch say); #For given/when since switch is being depricated
no warnings 'experimental::smartmatch';
sub usage{
print STDERR ("Usage: xacman [OPERATION/OPTION] [PACKAGE NAME]\n");
print STDERR ("EXAMPLE: xacman -Sy tilda; xacman --refresh tilda\n");
#Operations
print STDERR ("OPERATIONS:\n");
print STDERR (" -S, --sync Install [PACKAGE NAME]\n");
print STDERR (" -R, --remove Remove [PACKAGE NAME]\n");
#Sync Options
print STDERR ("Sync Options:\n");
print STDERR (" s, --search Search for packages\n");
print STDERR (" y, --refresh Refresh package list\n");
print STDERR (" u, --upgrade Update [PACKAGE NAME]\n");
}
sub xbps{ ## How I execute code
exec("@_");
}
my $xbI = 'xbps-install';
my $xbQ = 'xbps-query';
my $xbR = 'xbps-remove';
my $action = $ARGV[0]; # Which xbps program to call
if (not $action){
usage(); exit 0;}
my $args = "@ARGV[1..$#ARGV]";
my $cmd = #which term to search/remove/install
#Pass a quotes to -Rs to list all packages
#Pass usage guide in case of -S
&{ sub {
if ($ARGV[1]){
return "$args"; #make cmd become a string of the args, quotes add spaces between args
}
elsif($action eq '-Ss'){
return '"" ';
}
elsif($action eq '-Sy'){
return "pass";
}
elsif($action eq '--refresh'){
return "pass";
}
elsif($action eq '-Su'){
return "pass";
}
elsif($action eq '-Syu'){
return "pass";
}
else{
return undef;
}
}
}();
if (not $cmd){ #If cmd is blank, with the exceptions above (the sub) then fail.
usage(); exit 0;}
#clear the variable so xbps doesn't try to search for it
if ($cmd eq "pass"){
$cmd = undef;}
given ($action) { #Try to keep all xbps commands grouped together $xbI/xbQ/etc
#Also can't figure out how to have multiple when conditions
#Such as when('-s' || '--sync')
#Xbps-install
$action = $xbI when ['-S','--sync'];
$action = "$xbI -u" when ['-Su', '--upgrade'];
$action = "$xbI -Su" when ['-Syu'];
$action = "$xbI -S" when ['-Sy','--refresh'];
#xbps-query
$action = "$xbQ -Rs" when ['-Ss', '--search'];
#xbps-remove
$action = $xbR when ['-R', '--remove'];
default { usage();exit 0; }
}
if ($cmd){
xbps($action, $cmd);
}
else{
xbps($action);
}