Skip to content

Commit

Permalink
CLI help text no longer contains redundant argument value lists
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Dec 16, 2023
1 parent 88bb1ba commit 2d99184
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@ import DAWFileKit

// Export

extension ExportProfileFormat: ExpressibleByArgument { }
extension ExportField: ExpressibleByArgument { }
extension ExportFolderFormat: ExpressibleByArgument { }
extension ExportProfileFormat: CustomExpressibleByArgument { }
extension ExportField: CustomExpressibleByArgument { }
extension ExportFolderFormat: CustomExpressibleByArgument { }

// Markers

extension MarkerIDMode: ExpressibleByArgument { }
extension MarkerImageFormat: ExpressibleByArgument { }
extension MarkerLabelProperties.AlignHorizontal: ExpressibleByArgument { }
extension MarkerLabelProperties.AlignVertical: ExpressibleByArgument { }
extension MarkersSource: ExpressibleByArgument { }
extension MarkerIDMode: CustomExpressibleByArgument { }
extension MarkerImageFormat: CustomExpressibleByArgument { }
extension MarkerLabelProperties.AlignHorizontal: CustomExpressibleByArgument { }
extension MarkerLabelProperties.AlignVertical: CustomExpressibleByArgument { }
extension MarkersSource: CustomExpressibleByArgument { }

// DAWFileKit Types

extension FinalCutPro.FCPXML.RoleType: ExpressibleByArgument { }
extension FinalCutPro.FCPXML.RoleType: CustomExpressibleByArgument { }

// CaseIterable suppression
// prevents ArgumentParser from writing out enum case allCases in the argument help.

protocol CustomExpressibleByArgument: ExpressibleByArgument { }

extension CustomExpressibleByArgument {
public static var allValueStrings: [String] { [] }
}

func caseIterableValueString<R: RawRepresentable>(
for type: R.Type
) -> String where R.RawValue == String, R: CaseIterable {
R.allCases.map { $0.rawValue }.joined(separator: " | ")
}
23 changes: 9 additions & 14 deletions Sources/markers-extractor-cli/MarkersExtractorCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
@Option(
help: ArgumentHelp(
"Metadata export format.",
valueName: ExportProfileFormat.allCases.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: ExportProfileFormat.self)
)
)
var exportFormat: ExportProfileFormat = MarkersExtractor.Settings.Defaults.exportFormat
Expand All @@ -36,8 +36,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
@Option(
help: ArgumentHelp(
"Annotations to import. If captions are used, their start timecode determines their position.",
valueName: MarkersSource.allCases
.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: MarkersSource.self)
)
)
var markersSource: MarkersSource = MarkersExtractor.Settings.Defaults.markersSource
Expand All @@ -54,7 +53,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
@Option(
help: ArgumentHelp(
"Marker thumb image format. 'gif' is animated and additional options can be specified with --gif-fps and --gif-span.",
valueName: MarkerImageFormat.allCases.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: MarkerImageFormat.self)
)
)
var imageFormat: MarkerImageFormat = MarkersExtractor.Settings.Defaults.imageFormat
Expand Down Expand Up @@ -95,8 +94,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
@Option(
help: ArgumentHelp(
"Marker naming mode. This affects Marker IDs and image filenames.",
valueName: MarkerIDMode.allCases
.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: MarkerIDMode.self)
)
)
var idNamingMode: MarkerIDMode = MarkersExtractor.Settings.Defaults.idNamingMode
Expand All @@ -105,7 +103,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
name: [.customLong("label")],
help: ArgumentHelp(
"Label to overlay on thumb images. This argument can be supplied more than once to apply multiple labels.",
valueName: "\(ExportField.allCases.map { $0.rawValue }.joined(separator: ", "))"
valueName: caseIterableValueString(for: ExportField.self)
)
)
var imageLabels: [ExportField] = []
Expand Down Expand Up @@ -166,8 +164,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
name: [.customLong("label-align-horizontal")],
help: ArgumentHelp(
"Horizontal alignment of image labels.",
valueName: MarkerLabelProperties.AlignHorizontal.allCases
.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: MarkerLabelProperties.AlignHorizontal.self)
)
)
var imageLabelAlignHorizontal: MarkerLabelProperties.AlignHorizontal = MarkersExtractor.Settings
Expand All @@ -177,8 +174,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
name: [.customLong("label-align-vertical")],
help: ArgumentHelp(
"Vertical alignment of image labels.",
valueName: MarkerLabelProperties.AlignVertical.allCases
.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: MarkerLabelProperties.AlignVertical.self)
)
)
var imageLabelAlignVertical: MarkerLabelProperties.AlignVertical = MarkersExtractor.Settings
Expand All @@ -203,8 +199,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
name: [.customLong("folder-format")],
help: ArgumentHelp(
"Output folder name format.",
valueName: ExportFolderFormat.allCases
.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: ExportFolderFormat.self)
)
)
var exportFolderFormat: ExportFolderFormat = MarkersExtractor.Settings.Defaults.exportFolderFormat
Expand All @@ -215,7 +210,7 @@ struct MarkersExtractorCLI: AsyncParsableCommand {
@Option(
help: ArgumentHelp(
"Log level.",
valueName: Logger.Level.allCases.map { $0.rawValue }.joined(separator: ", ")
valueName: caseIterableValueString(for: Logger.Level.self)
)
)
var logLevel: Logger.Level = .info
Expand Down

0 comments on commit 2d99184

Please sign in to comment.