From 2d9918426c8685187e9874a3cf2e4d659237719c Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Sat, 16 Dec 2023 02:24:54 -0800 Subject: [PATCH] CLI help text no longer contains redundant argument value lists --- .../Extensions/Types+ArgumentParser.swift | 33 ++++++++++++++----- .../MarkersExtractorCLI.swift | 23 +++++-------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Sources/markers-extractor-cli/Extensions/Types+ArgumentParser.swift b/Sources/markers-extractor-cli/Extensions/Types+ArgumentParser.swift index dcbf04b..36e7c78 100644 --- a/Sources/markers-extractor-cli/Extensions/Types+ArgumentParser.swift +++ b/Sources/markers-extractor-cli/Extensions/Types+ArgumentParser.swift @@ -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( + for type: R.Type +) -> String where R.RawValue == String, R: CaseIterable { + R.allCases.map { $0.rawValue }.joined(separator: " | ") +} diff --git a/Sources/markers-extractor-cli/MarkersExtractorCLI.swift b/Sources/markers-extractor-cli/MarkersExtractorCLI.swift index a23dc86..b15f0de 100644 --- a/Sources/markers-extractor-cli/MarkersExtractorCLI.swift +++ b/Sources/markers-extractor-cli/MarkersExtractorCLI.swift @@ -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 @@ -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 @@ -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 @@ -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 @@ -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] = [] @@ -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 @@ -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 @@ -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 @@ -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