Skip to content

Commit 52ca1a3

Browse files
committed
added 'file get-uti'
1 parent 6d0251c commit 52ca1a3

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

Sources/utiluti/FileCommands.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
//
2-
// File.swift
2+
// FileCommands.swift
33
// utiluti
44
//
55
// Created by Armin on 25/03/2025.
66
//
77

88
import Foundation
9+
10+
import Foundation
11+
import ArgumentParser
12+
import UniformTypeIdentifiers
13+
import AppKit // for NSWorkspace
14+
15+
struct FileCommands: ParsableCommand {
16+
static let configuration = CommandConfiguration(
17+
commandName: "file",
18+
abstract: "commands to manage specific files",
19+
subcommands: [ GetUTI.self ]
20+
)
21+
22+
struct GetUTI: ParsableCommand {
23+
static let configuration
24+
= CommandConfiguration(abstract: "get the uniform type identifier of a file")
25+
26+
@Argument(help:ArgumentHelp("file path", valueName: "path"))
27+
var path: String
28+
29+
func run() {
30+
let url = URL(fileURLWithPath: path)
31+
let typeIdentifier = try? url.resourceValues(forKeys: [.typeIdentifierKey]).typeIdentifier
32+
print(typeIdentifier ?? "<unknown>")
33+
}
34+
}
35+
}
36+

Sources/utiluti/utiluti.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import ArgumentParser
66

77
@main
88
struct UtilUTI: ParsableCommand {
9-
static let subCommands: [ParsableCommand.Type] = {
10-
if #available(macOS 11.0, *) {
11-
return [URLCommands.self, TypeCommands.self, GetUTI.self, AppCommands.self]
12-
} else {
13-
return [URLCommands.self, TypeCommands.self]
14-
}
15-
}()
9+
static let subCommands: [ParsableCommand.Type] = [URLCommands.self, TypeCommands.self, GetUTI.self, AppCommands.self, FileCommands.self]
1610

1711
static let configuration = CommandConfiguration(
1812
commandName: "utiluti",

0 commit comments

Comments
 (0)