-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.java
More file actions
124 lines (112 loc) · 3.84 KB
/
Command.java
File metadata and controls
124 lines (112 loc) · 3.84 KB
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
/**
* <h3> COMP90041, Sem2, 2022: Final Project </h3>
* <p>Class Command contains method to take in command line flags and call approriate menu
* @author Gia Han Ly
*/
public class Command {
private String jobsFile = "jobs.csv";
private String applicantFile = "applications.csv";
private String role;
// Setter and getter
/**
* Get user role
* @return role
*/
public String getRole(){
return role;
}
/**
* Get applications file name
* @return file name
*/
public String getApplicationsFile(){
return applicantFile;
}
/**
* Get jobs file name
* @return file name
*/
public String getJobsFile(){
return jobsFile;
}
/**
* <p> Read command line flags
* @param args - command line flag
* @author Gia Han Ly
*/
public void readCommand(String[] args){
if (args.length == 0){
this.printHelp();
}
// Read flag from command line input
for (int c =0; c< args.length; c++){
if (args[c].charAt(0) == '-'){
if(args[c].equals("-h") || args[c].equals("--help")){
this.printHelp();
}
else if(args[c].equals("-r") || args[c].equals("--role")){
if(c+1 >= args.length){
System.out.println("ERROR: no role defined");
this.printHelp();
}
else if (args[c+1].equals("applicant") || args[c+1].equals("hr") || args[c+1].equals("audit")){
this.role = args[c+1];
}
else if (args[c+1].equals("") || args[c+1].charAt(0) == '-'){
System.out.println("ERROR: no role defined.");
this.printHelp();
}
else{
System.out.println("ERROR: " + args[c+1] + " is not a valid role.");
this.printHelp();
}
c++;
}
else if(args[c].equals("-j") || args[c].equals("--jobs")){
if (c+1 >= args.length){
this.printHelp();
}
else if (args[c+1].equals("") || args[c+1].charAt(0) == '-' || args[c+1].equals(" ")){
this.printHelp();
}
else{
this.jobsFile = args[c+1];
c++;
}
}
else if(args[c].equals("-a") || args[c].equals("--applications")){
if (c+1 >= args.length){
this.printHelp();
}
else if (args[c+1].equals("") || args[c+1].charAt(0) == '-' || args[c+1].equals(" ")){
this.printHelp();
}
else{
this.applicantFile = args[c+1];
c++;
}
}
}
else {
this.printHelp();
}
}
if (this.role == null){
this.printHelp();
}
}
/**
* <p> Print help menu and exit the program
*/
private void printHelp(){
String help = "HRAssistant - COMP90041 - Final Project\n\n" +
"Usage: java HRAssistant [arguments]\n\n" +
"Arguments:\n" +
" -r or --role Mandatory: determines the user's role\n" +
" -a or --applications Optional: path to applications file\n" +
" -j or --jobs Optional: path to jobs file\n" +
" -h or --help Optional: print Help (this message) and exit\n";
System.out.print(help);
System.exit(0);
}
}