Skip to content

Commit 2d1162f

Browse files
committed
Added states:list example command
1 parent 23eaf72 commit 2d1162f

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

app/Commands/StatesListCommand.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Command} from 'grind-cli'
2+
3+
import 'App/Models/StateModel'
4+
5+
export class StatesListCommand extends Command {
6+
// Name of the command
7+
name = 'states:list'
8+
9+
// Description of the command to show in help
10+
description = 'List all states in the database'
11+
12+
// Arguments available for this command
13+
arguments = [ 'term?' ]
14+
15+
// Options for this command
16+
options = {
17+
limit: 'Limit the number of states'
18+
}
19+
20+
run() {
21+
const limit = Number.parseInt(this.option('limit', 100))
22+
let query = null
23+
24+
if(this.containsArgument('term')) {
25+
query = StateModel.find(this.argument('term'))
26+
} else {
27+
query = StateModel.query()
28+
}
29+
30+
return query.limit(limit).then(rows => {
31+
for(const row of rows) {
32+
this.comment(row.name)
33+
}
34+
})
35+
}
36+
37+
}

app/Providers/CommandsProvider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export function CommandsProvider(app) {
2-
// app.get('cli').register(
1+
import 'App/Commands/StatesListCommand'
32

4-
// )
3+
export function CommandsProvider(app) {
4+
app.get('cli').register(StatesListCommand)
55
}

0 commit comments

Comments
 (0)