|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -import * as program from 'commander'; |
4 | | -import * as os from 'os'; |
5 | | -import * as path from 'path'; |
| 3 | +import { Command } from 'commander'; |
| 4 | +import { homedir as osHomedir } from 'os'; |
| 5 | +import { join as joinPath } from 'path'; |
| 6 | + |
6 | 7 | import { listOutdated, Options } from '../lib'; |
7 | 8 |
|
8 | 9 | const pkg = require('../../package.json'); |
| 10 | +interface CliOptions { |
| 11 | + readonly composeFile: string; |
| 12 | + readonly dockerConfig: string; |
| 13 | + readonly filter: string; |
| 14 | + readonly excludeOfficalsAndInvalids: boolean; |
| 15 | +} |
9 | 16 |
|
10 | | -program.version(pkg.version) |
| 17 | +const program = new Command() |
| 18 | + .version(pkg.version) |
11 | 19 | .option('--compose-file <file path>', 'Path to the docker-compose file. Defaults to ./docker-compose.yml') |
12 | | - .option('--docker-config <file path>', 'Path to the docker config file, from which authentication details taken. Defaults to ~/.docker/config.json') |
13 | | - .option('-f --filter <string>', 'Filter string to optionally filter the list of checked-images. If specified, only images-names that contain the given search string will be checked') |
14 | | - .option('-x --exclude-officals-and-invalids', 'When scanning the docker-compose.yml file, exclude all images from the offical docker registry, as well as images that do not have a semver compliant tag') |
| 20 | + .option( |
| 21 | + '--docker-config <file path>', |
| 22 | + 'Path to the docker config file, from which authentication details taken. Defaults to ~/.docker/config.json' |
| 23 | + ) |
| 24 | + .option( |
| 25 | + '-f --filter <string>', |
| 26 | + 'Filter string to optionally filter the list of checked-images. If specified, only images-names that contain the given search string will be checked' |
| 27 | + ) |
| 28 | + .option( |
| 29 | + '-x --exclude-officals-and-invalids', |
| 30 | + 'When scanning the docker-compose.yml file, exclude all images from the offical docker registry, as well as images that do not have a semver compliant tag' |
| 31 | + ) |
15 | 32 | .parse(process.argv); |
16 | 33 |
|
17 | 34 | const options: Options = { |
18 | 35 | composeFilePath: './docker-compose.yml', |
19 | | - dockerConfigPath: path.join(os.homedir(), '.docker', 'config.json') |
| 36 | + dockerConfigPath: joinPath(osHomedir(), '.docker', 'config.json') |
20 | 37 | }; |
21 | 38 |
|
22 | | -if(program.composeFile) options.composeFilePath = program.composeFile; |
23 | | -if(program.dockerConfig) options.dockerConfigPath = program.dockerConfig; |
24 | | -if(program.filter) options.imagesFilter = program.filter; |
25 | | -if(program.excludeOfficalsAndInvalids) options.excludeOfficalsAndInvalids = true; |
| 39 | +const cliOptions = program.opts<CliOptions>(); |
26 | 40 |
|
| 41 | +if (cliOptions.composeFile) options.composeFilePath = cliOptions.composeFile; |
| 42 | +if (cliOptions.dockerConfig) options.dockerConfigPath = cliOptions.dockerConfig; |
| 43 | +if (cliOptions.filter) options.imagesFilter = cliOptions.filter; |
| 44 | +if (cliOptions.excludeOfficalsAndInvalids) options.excludeOfficalsAndInvalids = true; |
27 | 45 |
|
28 | | -listOutdated(options) |
29 | | - .catch(err => { |
30 | | - console.error(`There was an error: ${err.message}`); |
31 | | - process.exit(1); |
32 | | - }); |
| 46 | +listOutdated(options).catch(err => { |
| 47 | + console.error(`There was an error: ${err.message}`); |
| 48 | + process.exit(1); |
| 49 | +}); |
0 commit comments