-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update parser #87
Update parser #87
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,7 @@ shadowJar { | |
} | ||
|
||
defaultTasks 'clean', 'test' | ||
|
||
run { | ||
enableAssertions = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,21 +38,27 @@ public AddTuteeCommand parse(String args) throws ParseException { | |
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, | ||
PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS, PREFIX_TAG, PREFIX_SUBJECT); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS) | ||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTuteeCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
// Hours is optional for adding a tutee and will be set to 0 if unspecified | ||
Hours hours; | ||
if (!arePrefixesPresent(argMultimap, PREFIX_HOURS)) { | ||
hours = new Hours("0"); | ||
} else { | ||
hours = ParserUtil.parseHours(argMultimap.getValue(PREFIX_HOURS).get()); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS); | ||
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); | ||
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); | ||
Hours hours = ParserUtil.parseHours(argMultimap.getValue(PREFIX_HOURS).get()); | ||
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); | ||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
Set<Subject> subjects = ParserUtil.parseSubjects(argMultimap.getAllValues(PREFIX_SUBJECT)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Removed dead code. Well done! |
||
//Person person = new Person(name, phone, email, address, hours, tagList, subjects); | ||
Tutee tutee = new Tutee(name, phone, email, address, hours, tagList, subjects); | ||
|
||
return new AddTuteeCommand(tutee); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,16 +38,23 @@ public AddTutorCommand parse(String args) throws ParseException { | |
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, | ||
PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS, PREFIX_TAG, PREFIX_SUBJECT); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS) | ||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTutorCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
// Hours is optional for adding a tutee and will be set to 0 if unspecified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good comments letting the reader know what the code does. Very readable, very demure! |
||
Hours hours; | ||
if (!arePrefixesPresent(argMultimap, PREFIX_HOURS)) { | ||
hours = new Hours("0"); | ||
} else { | ||
hours = ParserUtil.parseHours(argMultimap.getValue(PREFIX_HOURS).get()); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_HOURS); | ||
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); | ||
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); | ||
Hours hours = ParserUtil.parseHours(argMultimap.getValue(PREFIX_HOURS).get()); | ||
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); | ||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
Set<Subject> subjects = ParserUtil.parseSubjects(argMultimap.getAllValues(PREFIX_SUBJECT)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,14 @@ | |
public class CliSyntax { | ||
|
||
/* Prefix definitions */ | ||
public static final Prefix PREFIX_NAME = new Prefix("-name "); | ||
public static final Prefix PREFIX_PHONE = new Prefix("-handphone "); | ||
public static final Prefix PREFIX_HOURS = new Prefix("-hours "); | ||
public static final Prefix PREFIX_EMAIL = new Prefix("-email "); | ||
public static final Prefix PREFIX_ADDRESS = new Prefix("-address "); | ||
public static final Prefix PREFIX_TAG = new Prefix("t/"); // TODO change? | ||
public static final Prefix PREFIX_SUBJECT = new Prefix("-subject "); | ||
public static final Prefix PREFIX_FILEPATH = new Prefix("-filepath "); | ||
public static final Prefix PREFIX_NAME = new Prefix("\\n "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remember to enable the disabled tests! |
||
public static final Prefix PREFIX_PHONE = new Prefix("\\p "); | ||
public static final Prefix PREFIX_HOURS = new Prefix("\\h "); | ||
public static final Prefix PREFIX_EMAIL = new Prefix("\\e "); | ||
public static final Prefix PREFIX_ADDRESS = new Prefix("\\a "); | ||
public static final Prefix PREFIX_TAG = new Prefix("\\t"); | ||
public static final Prefix PREFIX_SUBJECT = new Prefix("\\s "); | ||
public static final Prefix PREFIX_FILEPATH = new Prefix("\\f "); | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Mingyang, I don't think command + space is the default shortcut for opening the terminal. Maybe you might want to look into this further?