Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 4 additions & 39 deletions Sources/CLI/cmd/agent/skills/AgentSkillsGetCommand.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import ArgumentParser
import Logging

#if canImport(SentrySwift)
@preconcurrency import SentrySwift
#endif

struct AgentSkillsGetCommand: ParsableCommand, GlobalOptionsProviding {
@OptionGroup var global: GlobalOptions

private static let logger = Logger(
label: "com.techprimate.apple-docs.agent-skills-get"
)

static let configuration = CommandConfiguration(
commandName: "get",
abstract: "Print a bundled Agent Skill."
Expand All @@ -21,37 +12,11 @@ struct AgentSkillsGetCommand: ParsableCommand, GlobalOptionsProviding {
var name: String

mutating func run() throws {
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
let context = SentryCommandContext.agentSkillsGet
let transaction = SentrySDK.startTransaction(
name: context.transactionName,
operation: "console.command",
bindToScope: true
)
for (key, value) in context.attributes {
transaction.setData(value: value, key: key)
}
SentrySDK.configureScope { scope in
scope.setContext(value: context.attributes, key: "cli")
}
let breadcrumb = Breadcrumb(
level: .info,
category: SentryConfiguration.breadcrumbCategory
)
breadcrumb.type = "user"
breadcrumb.message = "CLI command invoked"
for (key, value) in context.attributes {
breadcrumb.setData(value: value, key: key)
}
SentrySDK.addBreadcrumb(breadcrumb)
Self.logger.info(
"CLI command started",
metadata: context.logMetadata
)
}
#endif
try run(telemetry: Dependencies.telemetry)
}

func run(telemetry: Telemetry) throws {
telemetry.startCommand(.agentSkillsGet)
guard let skill = BundledAgentSkills.skill(named: name) else {
throw ValidationError("Unknown bundled Agent Skill '\(name)'.")
}
Expand Down
43 changes: 4 additions & 39 deletions Sources/CLI/cmd/agent/skills/AgentSkillsListCommand.swift
Original file line number Diff line number Diff line change
@@ -1,54 +1,19 @@
import ArgumentParser
import Logging

#if canImport(SentrySwift)
@preconcurrency import SentrySwift
#endif

struct AgentSkillsListCommand: ParsableCommand, GlobalOptionsProviding {
@OptionGroup var global: GlobalOptions

private static let logger = Logger(
label: "com.techprimate.apple-docs.agent-skills-list"
)

static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List Agent Skills bundled with apple-docs."
)

mutating func run() throws {
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
let context = SentryCommandContext.agentSkillsList
let transaction = SentrySDK.startTransaction(
name: context.transactionName,
operation: "console.command",
bindToScope: true
)
for (key, value) in context.attributes {
transaction.setData(value: value, key: key)
}
SentrySDK.configureScope { scope in
scope.setContext(value: context.attributes, key: "cli")
}
let breadcrumb = Breadcrumb(
level: .info,
category: SentryConfiguration.breadcrumbCategory
)
breadcrumb.type = "user"
breadcrumb.message = "CLI command invoked"
for (key, value) in context.attributes {
breadcrumb.setData(value: value, key: key)
}
SentrySDK.addBreadcrumb(breadcrumb)
Self.logger.info(
"CLI command started",
metadata: context.logMetadata
)
}
#endif
run(telemetry: Dependencies.telemetry)
}

func run(telemetry: Telemetry) {
telemetry.startCommand(.agentSkillsList)
for skill in BundledAgentSkills.all {
print("\(skill.name)\t\(skill.shortDescription)")
}
Expand Down
43 changes: 4 additions & 39 deletions Sources/CLI/cmd/cache/CacheCleanCommand.swift
Original file line number Diff line number Diff line change
@@ -1,54 +1,19 @@
import ArgumentParser
import Logging

#if canImport(SentrySwift)
@preconcurrency import SentrySwift
#endif

struct CacheCleanCommand: ParsableCommand, GlobalOptionsProviding {
@OptionGroup var global: GlobalOptions

private static let logger = Logger(
label: "com.techprimate.apple-docs.cache-clean"
)

static let configuration = CommandConfiguration(
commandName: "clean",
abstract: "Clear cached Apple documentation."
)

mutating func run() throws {
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
let context = SentryCommandContext.cacheClean
let transaction = SentrySDK.startTransaction(
name: context.transactionName,
operation: "console.command",
bindToScope: true
)
for (key, value) in context.attributes {
transaction.setData(value: value, key: key)
}
SentrySDK.configureScope { scope in
scope.setContext(value: context.attributes, key: "cli")
}
let breadcrumb = Breadcrumb(
level: .info,
category: SentryConfiguration.breadcrumbCategory
)
breadcrumb.type = "user"
breadcrumb.message = "CLI command invoked"
for (key, value) in context.attributes {
breadcrumb.setData(value: value, key: key)
}
SentrySDK.addBreadcrumb(breadcrumb)
Self.logger.info(
"CLI command started",
metadata: context.logMetadata
)
}
#endif
run(telemetry: Dependencies.telemetry)
}

func run(telemetry: Telemetry) {
telemetry.startCommand(.cacheClean)
let result = CacheCleanCommandRunner(
cache: Dependencies.documentationCache
).run()
Expand Down
54 changes: 6 additions & 48 deletions Sources/CLI/cmd/technologies/TechnologiesListCommand.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import ArgumentParser
import Logging

#if canImport(SentrySwift)
@preconcurrency import SentrySwift
#endif

struct TechnologiesListCommand: AsyncParsableCommand, GlobalOptionsProviding {
@OptionGroup var global: GlobalOptions

private static let logger = Logger(
label: "com.techprimate.apple-docs.technologies-list"
)

static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List Apple documentation technologies."
Expand All @@ -24,50 +15,17 @@ struct TechnologiesListCommand: AsyncParsableCommand, GlobalOptionsProviding {
var json = false

mutating func run() async throws {
let context = SentryCommandContext.technologiesList(json: json)
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
let transaction = SentrySDK.startTransaction(
name: context.transactionName,
operation: "console.command",
bindToScope: true
)
for (key, value) in context.attributes {
transaction.setData(value: value, key: key)
}
SentrySDK.configureScope { scope in
scope.setContext(value: context.attributes, key: "cli")
}
let breadcrumb = Breadcrumb(
level: .info,
category: SentryConfiguration.breadcrumbCategory
)
breadcrumb.type = "user"
breadcrumb.message = "CLI command invoked"
for (key, value) in context.attributes {
breadcrumb.setData(value: value, key: key)
}
SentrySDK.addBreadcrumb(breadcrumb)
Self.logger.info(
"CLI command started",
metadata: context.logMetadata
)
}
#endif
try await run(telemetry: Dependencies.telemetry)
}

func run(telemetry: Telemetry) async throws {
let context = TelemetryCommandContext.technologiesList(json: json)
telemetry.startCommand(context)
let result = try await TechnologiesListCommandRunner(
client: Dependencies.documentationClient,
renderer: Dependencies.technologyListRenderer(json: json)
).run()
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
SentrySDK.metrics.gauge(
key: "apple_docs.technology.catalog.count",
value: Double(result.technologyCount),
attributes: context.metricAttributes
)
}
#endif
telemetry.record(.technologyCatalog(count: result.technologyCount), context: context)
print(result.output)
}
}
57 changes: 6 additions & 51 deletions Sources/CLI/cmd/types/TypesListCommand.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import ArgumentParser
import Logging

#if canImport(SentrySwift)
@preconcurrency import SentrySwift
#endif

struct TypesListCommand: AsyncParsableCommand, GlobalOptionsProviding {
@OptionGroup var global: GlobalOptions

private static let logger = Logger(
label: "com.techprimate.apple-docs.types-list"
)

static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List types in an Apple documentation technology."
Expand All @@ -27,53 +18,17 @@ struct TypesListCommand: AsyncParsableCommand, GlobalOptionsProviding {
var json = false

mutating func run() async throws {
let context = SentryCommandContext.typesList(
technology: technology,
json: json
)
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
let transaction = SentrySDK.startTransaction(
name: context.transactionName,
operation: "console.command",
bindToScope: true
)
for (key, value) in context.attributes {
transaction.setData(value: value, key: key)
}
SentrySDK.configureScope { scope in
scope.setContext(value: context.attributes, key: "cli")
}
let breadcrumb = Breadcrumb(
level: .info,
category: SentryConfiguration.breadcrumbCategory
)
breadcrumb.type = "user"
breadcrumb.message = "CLI command invoked"
for (key, value) in context.attributes {
breadcrumb.setData(value: value, key: key)
}
SentrySDK.addBreadcrumb(breadcrumb)
Self.logger.info(
"CLI command started",
metadata: context.logMetadata
)
}
#endif
try await run(telemetry: Dependencies.telemetry)
}

func run(telemetry: Telemetry) async throws {
let context = TelemetryCommandContext.typesList(technology: technology, json: json)
telemetry.startCommand(context)
let result = try await TypesListCommandRunner(
client: Dependencies.documentationClient,
renderer: Dependencies.documentationTypeListRenderer(json: json)
).run(technology: technology)
#if canImport(SentrySwift)
if SentrySDK.isEnabled {
SentrySDK.metrics.gauge(
key: "apple_docs.type.catalog.count",
value: Double(result.typeCount),
attributes: context.metricAttributes
)
}
#endif
telemetry.record(.typeCatalog(count: result.typeCount), context: context)
print(result.output)
}
}
Loading
Loading