-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatcomm.pl
141 lines (117 loc) · 2.49 KB
/
catcomm.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
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
#!/usr/bin/perl
require "client.pl";
require "server.pl";
require "catCommsIndex.pl";
require "config.pl";
sub printHelp()
{
print<<EOF;
NAME
catcomm
SYNOPSIS
catcomm [start|stop|sync|--help] address port
catcomm [add|remove|show|categories|remove_category|add_category| -h] fileName categories
DESCRIPTION
start
Start the catcomm server
stop
Stop the catcomm server
sync
Sync files with all peers configured in config.xml
address
If an address is specified for the sync command, catcomm will only
exchange files with the specified host.
port
If a port is specified for the sync command, catcomm will only
exchange files with the specified host.
NOTE: this option MUST be used alongside the address option
add fileName [categories]
Add a file to the index
remove fileName
Remove a file from the index
show
List all files in the index
categories fileName
List all categories for a specified file
remove_category fileName categoryName
Remove a specified category for a file
add_category fileName categoryName
Add a spefified category for a file
--help
Print this message
AUTHOR
Written by Nikola Sobadzhiev.
EOF
}
parseConfig();
my $command = shift;
if ($command eq "start")
{
my $serverPort = serverPort();
startServer($serverPort);
}
elsif ($command eq "stop")
{
stopServer();
}
elsif ($command eq "sync")
{
my $host = shift;
my $port = shift;
if ($host and $port)
{
syncWithPeer($host, $port);
}
else
{
syncWithAllPeers();
}
}
if ($command eq "add")
{
$fileName = shift || printHelp();
@categories = @ARGV || printHelp();
addFileWithCategories($fileName, @categories);
}
elsif ($command eq "remove")
{
$fileName = shift || printHelp();
removeFile($fileName);
}
elsif ($command eq "show")
{
@allFiles = allFilePaths();
foreach $file (@allFiles)
{
print("\t" . $file . "\n");
}
}
elsif ($command eq "categories")
{
$fileName = shift || printHelp();
@allCategories = categoriesForFile($fileName);
foreach $category (@allCategories)
{
print("\t" . $category . "\n");
}
}
elsif ($command eq "remove_category")
{
$fileName = shift || printHelp();
$category = shift || printHelp();
removeCategoryForFile($fileName, $category);
}
elsif ($command eq "add_category")
{
$fileName = shift || printHelp();
$category = shift || printHelp();
addCategoryForFile($fileName, $category);
}
elsif ($command eq "--help")
{
printHelp();
}
else
{
printHelp();
}