MCPcopy Index your code
hub / github.com/cloudgraphdev/cli / run

Method run

src/commands/scan.ts:104–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102 }
103
104 async run(): Promise<void> {
105 const { argv, flags } = await this.parse(Scan)
106 const { dev: devMode } = flags as {
107 [flag: string]: any
108 }
109
110 const { dataDir } = this.config
111 const opts: Opts = { logger: this.logger, debug: true, devMode }
112 let allProviders = argv
113
114 // Run dgraph health check
115 const storageEngine = (await this.getStorageEngine()) as DgraphEngine
116 const storageRunning = await storageEngine.healthCheck()
117 /**
118 * Handle 2 methods of scanning, either for explicitly passed providers OR
119 * try to scan for all providers found within the config file
120 * if we still have 0 providers, fail and exit.
121 */
122 if (allProviders.length >= 1) {
123 this.logger.debug(`Scanning for providers: ${allProviders}`)
124 } else {
125 this.logger.debug('Scanning for providers found in config')
126 const config = this.getCGConfig()
127
128 allProviders = Object.keys(config).filter(
129 (val: string) => val !== 'cloudGraph'
130 )
131 if (allProviders.length === 0) {
132 this.logger.error(
133 'There are no providers configured and none were passed to scan'
134 )
135 this.exit()
136 }
137 }
138
139 // Build folder structure for saving CloudGraph data by version
140 const schema: any[] = []
141 let folders = fileUtils.getVersionFolders(
142 path.join(dataDir, this.versionDirectory)
143 )
144 let dataFolder = 'version-1'
145
146 if (folders.length >= this.versionLimit) {
147 this.logger.warn(
148 `Maximum number of data versions has been reached, deleting version-1 and creating a new version-${this.versionLimit}`
149 )
150 // version 1 gets deleted, version 2 becomes version 1 … new version gets created
151 const pathPrefix = path.join(dataDir, this.versionDirectory)
152 const versionPrefix = path.join(pathPrefix, 'version-')
153 for (const version of [
154 1,
155 ...range(this.versionLimit + 1, folders.length + 1),
156 ]) {
157 fs.rmSync(versionPrefix + version, { recursive: true })
158 }
159 for (const version of range(1, this.versionLimit)) {
160 fs.renameSync(versionPrefix + (version + 1), versionPrefix + version)
161 }

Callers

nothing calls this directly

Calls 9

pluginsMethod · 0.95
loadAllDataFunction · 0.90
healthCheckMethod · 0.80
pushMethod · 0.80
getSchemaMethod · 0.80
validateSchemaMethod · 0.80
dropAllMethod · 0.80
setSchemaMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected