-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ecf6c5
commit cc0c8c2
Showing
12 changed files
with
664 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* @adonisjs/ace | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { CommandArg, ArgTypes } from '../Contracts' | ||
|
||
type DecoratorArg = Partial<Pick<CommandArg, Exclude<keyof CommandArg, 'type'>>> | ||
|
||
/** | ||
* Adds arg to the list of command arguments with pre-defined | ||
* type. | ||
*/ | ||
function addArg (type: ArgTypes, options: DecoratorArg) { | ||
return function arg (target: any, propertyKey: string) { | ||
const arg: CommandArg = Object.assign({ | ||
type, | ||
name: propertyKey, | ||
required: true, | ||
}, options) | ||
|
||
if (!target.constructor.hasOwnProperty('args')) { | ||
Object.defineProperty(target.constructor, 'args', { value: [] }) | ||
} | ||
|
||
target.constructor.args.push(arg) | ||
} | ||
} | ||
|
||
export const args = { | ||
/** | ||
* Define argument that accepts string value | ||
*/ | ||
string (options?: Partial<CommandArg>) { | ||
return addArg('string', options || {}) | ||
}, | ||
|
||
/** | ||
* Define argument that accepts multiple values. Must be | ||
* the last argument. | ||
*/ | ||
spread (options?: Partial<CommandArg>) { | ||
return addArg('spread', options || {}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* @adonisjs/ace | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { Exception } from '@poppinss/utils' | ||
|
||
export class InvalidArgumentException extends Exception { | ||
public static invalidType (prop: string, expected: string) { | ||
const message = `${prop} must be defined as a ${expected}` | ||
return new InvalidArgumentException(message, 500) | ||
} | ||
|
||
public static missingArgument (name: string) { | ||
const message = `missing required argument ${name}` | ||
return new InvalidArgumentException(message, 500) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.