|
1 | 1 | const { program } = require('commander'); |
2 | 2 | const { MBNDSynchronizer } = require('./lib/handlers/MBNDSynchronizer.js'); |
| 3 | +const packageJson = require('./package.json'); |
3 | 4 |
|
4 | 5 | const runAction = async (options, command) => { |
5 | 6 | const synchronizer = new MBNDSynchronizer(options); |
6 | 7 | await synchronizer.run(command._name); |
7 | 8 | }; |
8 | 9 |
|
| 10 | +const commandLinesOptions = { |
| 11 | + csv: { |
| 12 | + flags: '--csv <path>', |
| 13 | + description: 'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS', |
| 14 | + defaultValue: 'MusicBee_Export.csv' |
| 15 | + }, |
| 16 | + db: { |
| 17 | + flags: '--db <path>', |
| 18 | + description: 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS', |
| 19 | + defaultValue: 'navidrome.db' |
| 20 | + }, |
| 21 | + user: { |
| 22 | + flags: '-u, --user <user_name>', |
| 23 | + description: 'choose Navidrome username (by default if not used, the first user will be used)' |
| 24 | + }, |
| 25 | + verbose: { |
| 26 | + flags: '--verbose', |
| 27 | + description: 'verbose debugging' |
| 28 | + } |
| 29 | +}; |
| 30 | + |
9 | 31 | program |
10 | 32 | .name('musicbee-navidrome-sync') |
11 | 33 | .description( |
12 | 34 | 'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync' |
13 | 35 | ) |
14 | | - .version('1.0.4', '-v, --version', 'output the current version'); |
| 36 | + .version(packageJson.version, '-v, --version', 'output the current version'); |
15 | 37 |
|
16 | 38 | program |
17 | 39 | .command('fullSync') |
18 | 40 | .description('sync playcounts, track ratings, loved tracks and last played from MusicBee DB to Navidrome DB') |
19 | | - .option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)') |
| 41 | + .option(commandLinesOptions.user.flags, commandLinesOptions.user.description) |
20 | 42 | .option('-f, --first', 'run sync for the first time: add MB playcount to ND playcount') |
21 | | - .option('--verbose', 'verbose debugging') |
22 | | - .option( |
23 | | - '--csv <path>', |
24 | | - 'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS', |
25 | | - 'MusicBee_Export.csv' |
26 | | - ) |
27 | | - .option( |
28 | | - '--db <path>', |
29 | | - 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS', |
30 | | - 'navidrome.db' |
31 | | - ) |
| 43 | + .option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description) |
| 44 | + .option(commandLinesOptions.csv.flags, commandLinesOptions.description, commandLinesOptions.defaultValue) |
| 45 | + .option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue) |
32 | 46 | .action(runAction); |
33 | 47 |
|
34 | 48 | program |
35 | 49 | .command('albumsSync') |
36 | 50 | .description('update all albums playcounts and ratings based on existing Navidrome DB') |
37 | | - .option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)') |
38 | | - .option('--verbose', 'verbose debugging') |
39 | | - .option( |
40 | | - '--db <path>', |
41 | | - 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS', |
42 | | - 'navidrome.db' |
43 | | - ) |
| 51 | + .option(commandLinesOptions.user.flags, commandLinesOptions.user.description) |
| 52 | + .option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description) |
| 53 | + .option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue) |
44 | 54 | .action(runAction); |
45 | 55 |
|
46 | 56 | program |
47 | 57 | .command('artistsSync') |
48 | 58 | .description('update all artists playcounts and ratings based on existing Navidrome DB') |
49 | | - .option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)') |
50 | | - .option('--verbose', 'verbose debugging') |
51 | | - .option( |
52 | | - '--db <path>', |
53 | | - 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS', |
54 | | - 'navidrome.db' |
55 | | - ) |
| 59 | + .option(commandLinesOptions.user.flags, commandLinesOptions.user.description) |
| 60 | + .option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description) |
| 61 | + .option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue) |
56 | 62 | .action(runAction); |
57 | 63 |
|
58 | 64 | program.parse(); |
0 commit comments