@@ -79,12 +79,6 @@ def _do_query(lib, query, album, also_items=True):
79
79
80
80
# fields: Shows a list of available fields for queries and format strings.
81
81
82
- fields_cmd = ui .Subcommand (
83
- 'fields' ,
84
- help = 'show fields available for queries and format strings'
85
- )
86
-
87
-
88
82
def fields_func (lib , opts , args ):
89
83
def _print_rows (names ):
90
84
print (" " + "\n " .join (names ))
@@ -109,6 +103,11 @@ def _show_plugin_fields(album):
109
103
_print_rows (library .Album ._fields .keys ())
110
104
_show_plugin_fields (True )
111
105
106
+
107
+ fields_cmd = ui .Subcommand (
108
+ 'fields' ,
109
+ help = 'show fields available for queries and format strings'
110
+ )
112
111
fields_cmd .func = fields_func
113
112
default_commands .append (fields_cmd )
114
113
@@ -796,6 +795,27 @@ def import_files(lib, paths, query):
796
795
# Emit event.
797
796
plugins .send ('import' , lib = lib , paths = paths )
798
797
798
+
799
+ def import_func (lib , opts , args ):
800
+ config ['import' ].set_args (opts )
801
+
802
+ # Special case: --copy flag suppresses import_move (which would
803
+ # otherwise take precedence).
804
+ if opts .copy :
805
+ config ['import' ]['move' ] = False
806
+
807
+ if opts .library :
808
+ query = decargs (args )
809
+ paths = []
810
+ else :
811
+ query = None
812
+ paths = args
813
+ if not paths :
814
+ raise ui .UserError ('no path specified' )
815
+
816
+ import_files (lib , paths , query )
817
+
818
+
799
819
import_cmd = ui .Subcommand (
800
820
'import' , help = 'import new music' , aliases = ('imp' , 'im' )
801
821
)
@@ -867,26 +887,6 @@ def import_files(lib, paths, query):
867
887
'-g' , '--group-albums' , dest = 'group_albums' , action = 'store_true' ,
868
888
help = 'group tracks in a folder into seperate albums'
869
889
)
870
-
871
-
872
- def import_func (lib , opts , args ):
873
- config ['import' ].set_args (opts )
874
-
875
- # Special case: --copy flag suppresses import_move (which would
876
- # otherwise take precedence).
877
- if opts .copy :
878
- config ['import' ]['move' ] = False
879
-
880
- if opts .library :
881
- query = decargs (args )
882
- paths = []
883
- else :
884
- query = None
885
- paths = args
886
- if not paths :
887
- raise ui .UserError ('no path specified' )
888
-
889
- import_files (lib , paths , query )
890
890
import_cmd .func = import_func
891
891
default_commands .append (import_cmd )
892
892
@@ -906,6 +906,14 @@ def list_items(lib, query, album, fmt):
906
906
ui .print_obj (item , lib , tmpl )
907
907
908
908
909
+ def list_func (lib , opts , args ):
910
+ if opts .path :
911
+ fmt = '$path'
912
+ else :
913
+ fmt = opts .format
914
+ list_items (lib , decargs (args ), opts .album , fmt )
915
+
916
+
909
917
list_cmd = ui .Subcommand ('list' , help = 'query the library' , aliases = ('ls' ,))
910
918
list_cmd .parser .add_option (
911
919
'-a' , '--album' , action = 'store_true' ,
@@ -919,14 +927,6 @@ def list_items(lib, query, album, fmt):
919
927
'-f' , '--format' , action = 'store' ,
920
928
help = 'print with custom format' , default = None
921
929
)
922
-
923
-
924
- def list_func (lib , opts , args ):
925
- if opts .path :
926
- fmt = '$path'
927
- else :
928
- fmt = opts .format
929
- list_items (lib , decargs (args ), opts .album , fmt )
930
930
list_cmd .func = list_func
931
931
default_commands .append (list_cmd )
932
932
@@ -1020,6 +1020,10 @@ def update_items(lib, query, album, move, pretend):
1020
1020
album .move ()
1021
1021
1022
1022
1023
+ def update_func (lib , opts , args ):
1024
+ update_items (lib , decargs (args ), opts .album , opts .move , opts .pretend )
1025
+
1026
+
1023
1027
update_cmd = ui .Subcommand (
1024
1028
'update' , help = 'update the library' , aliases = ('upd' , 'up' ,)
1025
1029
)
@@ -1039,12 +1043,6 @@ def update_items(lib, query, album, move, pretend):
1039
1043
'-f' , '--format' , action = 'store' ,
1040
1044
help = 'print with custom format' , default = None
1041
1045
)
1042
-
1043
-
1044
- def update_func (lib , opts , args ):
1045
- update_items (lib , decargs (args ), opts .album , opts .move , opts .pretend )
1046
-
1047
-
1048
1046
update_cmd .func = update_func
1049
1047
default_commands .append (update_cmd )
1050
1048
@@ -1078,6 +1076,10 @@ def remove_items(lib, query, album, delete):
1078
1076
obj .remove (delete )
1079
1077
1080
1078
1079
+ def remove_func (lib , opts , args ):
1080
+ remove_items (lib , decargs (args ), opts .album , opts .delete )
1081
+
1082
+
1081
1083
remove_cmd = ui .Subcommand (
1082
1084
'remove' , help = 'remove matching items from the library' , aliases = ('rm' ,)
1083
1085
)
@@ -1089,12 +1091,6 @@ def remove_items(lib, query, album, delete):
1089
1091
'-a' , '--album' , action = 'store_true' ,
1090
1092
help = 'match albums instead of tracks'
1091
1093
)
1092
-
1093
-
1094
- def remove_func (lib , opts , args ):
1095
- remove_items (lib , decargs (args ), opts .album , opts .delete )
1096
-
1097
-
1098
1094
remove_cmd .func = remove_func
1099
1095
default_commands .append (remove_cmd )
1100
1096
@@ -1133,19 +1129,17 @@ def show_stats(lib, query, exact):
1133
1129
size_str , len (artists ), len (albums )))
1134
1130
1135
1131
1132
+ def stats_func (lib , opts , args ):
1133
+ show_stats (lib , decargs (args ), opts .exact )
1134
+
1135
+
1136
1136
stats_cmd = ui .Subcommand (
1137
1137
'stats' , help = 'show statistics about the library or a query'
1138
1138
)
1139
1139
stats_cmd .parser .add_option (
1140
1140
'-e' , '--exact' , action = 'store_true' ,
1141
1141
help = 'get exact file sizes'
1142
1142
)
1143
-
1144
-
1145
- def stats_func (lib , opts , args ):
1146
- show_stats (lib , decargs (args ), opts .exact )
1147
-
1148
-
1149
1143
stats_cmd .func = stats_func
1150
1144
default_commands .append (stats_cmd )
1151
1145
@@ -1256,6 +1250,17 @@ def modify_parse_args(args):
1256
1250
query .append (arg )
1257
1251
return query , mods , dels
1258
1252
1253
+
1254
+ def modify_func (lib , opts , args ):
1255
+ query , mods , dels = modify_parse_args (decargs (args ))
1256
+ if not mods and not dels :
1257
+ raise ui .UserError ('no modifications specified' )
1258
+ write = opts .write if opts .write is not None else \
1259
+ config ['import' ]['write' ].get (bool )
1260
+ modify_items (lib , mods , dels , query , write , opts .move , opts .album ,
1261
+ not opts .yes )
1262
+
1263
+
1259
1264
modify_cmd = ui .Subcommand (
1260
1265
'modify' , help = 'change metadata fields' , aliases = ('mod' ,)
1261
1266
)
@@ -1283,18 +1288,6 @@ def modify_parse_args(args):
1283
1288
'-f' , '--format' , action = 'store' ,
1284
1289
help = 'print with custom format' , default = None
1285
1290
)
1286
-
1287
-
1288
- def modify_func (lib , opts , args ):
1289
- query , mods , dels = modify_parse_args (decargs (args ))
1290
- if not mods and not dels :
1291
- raise ui .UserError ('no modifications specified' )
1292
- write = opts .write if opts .write is not None else \
1293
- config ['import' ]['write' ].get (bool )
1294
- modify_items (lib , mods , dels , query , write , opts .move , opts .album ,
1295
- not opts .yes )
1296
-
1297
-
1298
1291
modify_cmd .func = modify_func
1299
1292
default_commands .append (modify_cmd )
1300
1293
@@ -1319,6 +1312,16 @@ def move_items(lib, dest, query, copy, album):
1319
1312
obj .store ()
1320
1313
1321
1314
1315
+ def move_func (lib , opts , args ):
1316
+ dest = opts .dest
1317
+ if dest is not None :
1318
+ dest = normpath (dest )
1319
+ if not os .path .isdir (dest ):
1320
+ raise ui .UserError ('no such directory: %s' % dest )
1321
+
1322
+ move_items (lib , dest , decargs (args ), opts .copy , opts .album )
1323
+
1324
+
1322
1325
move_cmd = ui .Subcommand (
1323
1326
'move' , help = 'move or copy items' , aliases = ('mv' ,)
1324
1327
)
@@ -1334,18 +1337,6 @@ def move_items(lib, dest, query, copy, album):
1334
1337
'-a' , '--album' , default = False , action = 'store_true' ,
1335
1338
help = 'match whole albums instead of tracks'
1336
1339
)
1337
-
1338
-
1339
- def move_func (lib , opts , args ):
1340
- dest = opts .dest
1341
- if dest is not None :
1342
- dest = normpath (dest )
1343
- if not os .path .isdir (dest ):
1344
- raise ui .UserError ('no such directory: %s' % dest )
1345
-
1346
- move_items (lib , dest , decargs (args ), opts .copy , opts .album )
1347
-
1348
-
1349
1340
move_cmd .func = move_func
1350
1341
default_commands .append (move_cmd )
1351
1342
@@ -1383,39 +1374,21 @@ def write_items(lib, query, pretend):
1383
1374
item .try_write ()
1384
1375
1385
1376
1377
+ def write_func (lib , opts , args ):
1378
+ write_items (lib , decargs (args ), opts .pretend )
1379
+
1380
+
1386
1381
write_cmd = ui .Subcommand ('write' , help = 'write tag information to files' )
1387
1382
write_cmd .parser .add_option (
1388
1383
'-p' , '--pretend' , action = 'store_true' ,
1389
1384
help = "show all changes but do nothing"
1390
1385
)
1391
-
1392
-
1393
- def write_func (lib , opts , args ):
1394
- write_items (lib , decargs (args ), opts .pretend )
1395
-
1396
-
1397
1386
write_cmd .func = write_func
1398
1387
default_commands .append (write_cmd )
1399
1388
1400
1389
1401
1390
# config: Show and edit user configuration.
1402
1391
1403
- config_cmd = ui .Subcommand ('config' ,
1404
- help = 'show or edit the user configuration' )
1405
- config_cmd .parser .add_option (
1406
- '-p' , '--paths' , action = 'store_true' ,
1407
- help = 'show files that configuration was loaded from'
1408
- )
1409
- config_cmd .parser .add_option (
1410
- '-e' , '--edit' , action = 'store_true' ,
1411
- help = 'edit user configuration with $EDITOR'
1412
- )
1413
- config_cmd .parser .add_option (
1414
- '-d' , '--defaults' , action = 'store_true' ,
1415
- help = 'include the default configuration'
1416
- )
1417
-
1418
-
1419
1392
def config_func (lib , opts , args ):
1420
1393
# Make sure lazy configuration is loaded
1421
1394
config .resolve ()
@@ -1466,18 +1439,26 @@ def config_func(lib, opts, args):
1466
1439
print (config .dump (full = opts .defaults ))
1467
1440
1468
1441
1442
+ config_cmd = ui .Subcommand ('config' ,
1443
+ help = 'show or edit the user configuration' )
1444
+ config_cmd .parser .add_option (
1445
+ '-p' , '--paths' , action = 'store_true' ,
1446
+ help = 'show files that configuration was loaded from'
1447
+ )
1448
+ config_cmd .parser .add_option (
1449
+ '-e' , '--edit' , action = 'store_true' ,
1450
+ help = 'edit user configuration with $EDITOR'
1451
+ )
1452
+ config_cmd .parser .add_option (
1453
+ '-d' , '--defaults' , action = 'store_true' ,
1454
+ help = 'include the default configuration'
1455
+ )
1469
1456
config_cmd .func = config_func
1470
1457
default_commands .append (config_cmd )
1471
1458
1472
1459
1473
1460
# completion: print completion script
1474
1461
1475
- completion_cmd = ui .Subcommand (
1476
- 'completion' ,
1477
- help = 'print shell script that provides command line completion'
1478
- )
1479
-
1480
-
1481
1462
def print_completion (* args ):
1482
1463
for line in completion_script (default_commands + plugins .commands ()):
1483
1464
print (line , end = '' )
@@ -1564,6 +1545,10 @@ def completion_script(commands):
1564
1545
yield '}\n '
1565
1546
1566
1547
1548
+ completion_cmd = ui .Subcommand (
1549
+ 'completion' ,
1550
+ help = 'print shell script that provides command line completion'
1551
+ )
1567
1552
completion_cmd .func = print_completion
1568
1553
completion_cmd .hide = True
1569
1554
default_commands .append (completion_cmd )
0 commit comments