@@ -13,122 +13,6 @@ struct UtilUTI: ParsableCommand {
1313 commandName: " utiluti " ,
1414 abstract: " Read and set default URL scheme and file type handlers. " ,
1515 subcommands: [ URLCommands . self, TypeCommands . self] )
16-
17- struct URLCommands : ParsableCommand {
18- static var configuration = CommandConfiguration (
19- commandName: " url " ,
20- abstract: " Manipulate default URL scheme handlers " ,
21- subcommands: [ Get . self, List . self, Set . self] ,
22- defaultSubcommand: Get . self)
23-
24- struct URLScheme : ParsableArguments {
25- @Argument ( help: " the url scheme, e.g. 'http' or 'mailto' " ) var urlScheme : String
26- }
27-
28- struct Get : ParsableCommand {
29- static var configuration
30- = CommandConfiguration ( abstract: " Get the path to the default application. " )
31-
32- @OptionGroup var args : URLScheme
33-
34- func run( ) {
35- let appURL = LSKit . defaultAppURL ( forScheme: args. urlScheme)
36- print ( appURL? . path ?? " no default app found " )
37- }
38- }
39-
40- struct List : ParsableCommand {
41- static var configuration
42- = CommandConfiguration ( abstract: " List all applications that can handle this URL scheme. " )
43-
44- @OptionGroup var args : URLScheme
45-
46- func run( ) {
47- let appURLs = LSKit . appURLs ( forScheme: args. urlScheme)
48-
49- for appURL in appURLs {
50- print ( appURL. path)
51- }
52- }
53- }
54-
55- struct Set : ParsableCommand {
56- static var configuration
57- = CommandConfiguration ( abstract: " Set the default app for this URL scheme. " )
58-
59- @OptionGroup var args : URLScheme
60- @Argument ( help: " bundle identifier for the app " ) var identifier : String
61-
62- func run( ) {
63- let result = LSKit . setDefaultApp ( identifier: identifier, forScheme: args. urlScheme)
64-
65- if result == 0 {
66- print ( " set \( identifier) for \( args. urlScheme) " )
67- } else {
68- print ( " cannot set default app for \( args. urlScheme) (error \( result) ) " )
69- }
70- }
71- }
72- }
73-
74- struct TypeCommands : ParsableCommand {
75- static var configuration = CommandConfiguration (
76- commandName: " type " ,
77- abstract: " Manipulate default file type handlers " ,
78- subcommands: [ Get . self, List . self, Set . self] ,
79- defaultSubcommand: Get . self
80- )
81-
82- struct UTIdentifier : ParsableArguments {
83- @Argument ( help: " universal type identifier, e.g. 'public.html' " ) var utidentifier : String
84- }
85-
86-
87- struct Get : ParsableCommand {
88- static var configuration
89- = CommandConfiguration ( abstract: " Get the path to the default application. " )
90-
91- @OptionGroup var args : UTIdentifier
92-
93- func run( ) {
94- let appURL = LSKit . defaultAppURL ( forTypeIdentifier: args. utidentifier)
95- print ( appURL? . path ?? " no default app found " )
96- }
97- }
98-
99- struct List : ParsableCommand {
100- static var configuration
101- = CommandConfiguration ( abstract: " List all applications that can handle this type identifier. " )
102-
103- @OptionGroup var args : UTIdentifier
104-
105- func run( ) {
106- let appURLs = LSKit . appURLs ( forTypeIdentifier: args. utidentifier)
107-
108- for appURL in appURLs {
109- print ( appURL. path)
110- }
111- }
112- }
113-
114- struct Set : ParsableCommand {
115- static var configuration
116- = CommandConfiguration ( abstract: " Set the default app for this type identifier. " )
117-
118- @OptionGroup var args : UTIdentifier
119- @Argument var identifier : String
120-
121- func run( ) {
122- let result = LSKit . setDefaultApp ( identifier: identifier, forTypeIdentifier: args. utidentifier)
123-
124- if result == 0 {
125- print ( " set \( identifier) for \( args. utidentifier) " )
126- } else {
127- print ( " cannot set default app for \( args. utidentifier) (error \( result) ) " )
128- }
129- }
130- }
131- }
13216}
13317
13418UtilUTI . main ( )
0 commit comments