1
- import Command , { flags } from '@oclif/command'
1
+ import Command from '@oclif/command'
2
2
import { Input } from '@oclif/parser'
3
3
import CloudGraph , { Logger } from '@cloudgraph/sdk'
4
4
import { cosmiconfigSync } from 'cosmiconfig'
5
- import path from 'path'
6
- import inquirer from 'inquirer'
7
5
import chalk from 'chalk'
6
+ import inquirer from 'inquirer'
7
+ import path from 'path'
8
8
import gt from 'semver/functions/gt'
9
9
import Manager from '../manager'
10
10
import EngineMap from '../storage'
11
11
import QueryEngine from '../server'
12
12
import { StorageEngine , StorageEngineConnectionConfig } from '../storage/types'
13
- import { getStorageEngineConnectionConfig , printWelcomeMessage , printBoxMessage } from '../utils'
13
+ import {
14
+ getDefaultEndpoint ,
15
+ getDefaultStorageEngineConnectionConfig ,
16
+ getStorageEngineConnectionConfig ,
17
+ printWelcomeMessage ,
18
+ printBoxMessage
19
+ } from '../utils'
20
+ import flagsDefinition from '../utils/flags'
14
21
import openBrowser from '../utils/open'
15
- import { DEFAULT_CONFIG } from '../utils/constants'
16
22
17
23
export default abstract class BaseCommand extends Command {
18
24
constructor ( argv : any , config : any ) {
@@ -37,49 +43,7 @@ export default abstract class BaseCommand extends Command {
37
43
38
44
storedConfig : { [ key : string ] : any } | undefined
39
45
40
- static flags = {
41
- // devMode flag
42
- dev : flags . boolean ( { description : 'Turn on developer mode' } ) ,
43
- // dgraph host
44
- dgraph : flags . string ( {
45
- char : 'd' ,
46
- env : 'CG_HOST_PORT' ,
47
- description : 'Set where dgraph is running (default localhost:8997)' ,
48
- } ) ,
49
- // storage engine to use
50
- storage : flags . string ( {
51
- char : 's' ,
52
- description :
53
- 'Select a storage engine to use. Currently only supports Dgraph' ,
54
- } ) ,
55
- // dir to store cloud graph data versions in
56
- directory : flags . string ( {
57
- description :
58
- 'Set the folder where CloudGraph will store data. (default cg)' ,
59
- } ) ,
60
- // serve query engine after scan/load
61
- 'no-serve' : flags . boolean ( {
62
- default : false ,
63
- description : 'Set to not serve a query engine' ,
64
- } ) ,
65
- // port for query engine
66
- port : flags . integer ( {
67
- char : 'p' ,
68
- env : 'CG_QUERY_PORT' ,
69
- description : 'Set port to serve query engine' ,
70
- } ) ,
71
- // Query Engine to use
72
- 'query-engine' : flags . string ( {
73
- char : 'q' ,
74
- description : 'Query engine to launch' ,
75
- } ) ,
76
- // version limit
77
- 'version-limit' : flags . string ( {
78
- char : 'l' ,
79
- description :
80
- 'Limit the amount of version folders stored on the filesystem (default 10)' ,
81
- } ) ,
82
- }
46
+ static flags = flagsDefinition
83
47
84
48
static hidden = true
85
49
@@ -205,12 +169,10 @@ Run ${chalk.italic.green('npm i -g @cloudgraph/cli')} to install`)
205
169
// nothing found, return default location
206
170
207
171
showInitialStatus &&
208
- this . logger . info (
209
- `Dgraph host set as: ${ DEFAULT_CONFIG . scheme } ://${ DEFAULT_CONFIG . host } :${ DEFAULT_CONFIG . port } `
210
- )
211
- return DEFAULT_CONFIG
172
+ this . logger . info ( `Dgraph host set as: ${ getDefaultEndpoint ( ) } ` )
173
+ return getDefaultStorageEngineConnectionConfig ( )
212
174
}
213
- return DEFAULT_CONFIG
175
+ return getDefaultStorageEngineConnectionConfig ( )
214
176
}
215
177
216
178
getHost ( config : StorageEngineConnectionConfig ) : string {
@@ -222,7 +184,11 @@ Run ${chalk.italic.green('npm i -g @cloudgraph/cli')} to install`)
222
184
flags : { dev : devMode } ,
223
185
} = this . parse ( this . constructor as Input < { dev : boolean } > )
224
186
if ( ! this . manager ) {
225
- this . manager = new Manager ( { logger : this . logger , devMode, cliConfig : this . config } )
187
+ this . manager = new Manager ( {
188
+ logger : this . logger ,
189
+ devMode,
190
+ cliConfig : this . config ,
191
+ } )
226
192
}
227
193
return this . manager
228
194
}
0 commit comments