this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve Type command with positional argument syntax

- Remove `-t` option requirement for cleaner syntax
- Add positional argument: `axe type "text" --udid UDID`
- Maintain backward compatibility with stdin and file input
- Improve error handling for unsupported characters
- Add comprehensive input validation and error messages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

+36 -12
+36 -12
Sources/AXe/Commands/Type.swift
··· 8 8 abstract: "Type text by entering a sequence of characters.", 9 9 discussion: """ 10 10 Input Methods: 11 - 1. Direct text: -t "Hello World" (use single quotes for special chars: -t 'Hello!') 11 + 1. Direct text: axe type "Hello World" --udid UDID 12 12 2. From stdin: echo "Hello World!" | axe type --stdin --udid UDID 13 13 3. From file: axe type --file text.txt --udid UDID 14 14 15 + Examples: 16 + • Simple text: axe type "Hello World" --udid UDID 17 + • With spaces: axe type "Hello, how are you?" --udid UDID 18 + • Special characters: axe type 'Hello!' --udid UDID 19 + 15 20 Shell Escaping Tips: 21 + • Use double quotes for text with spaces: "Hello World" 16 22 • Use single quotes for text with special characters: 'Hello!' 17 - • Use double quotes for simple text: "Hello World" 18 - • For automation, prefer --stdin or --file methods 23 + • For complex text or automation, prefer --stdin or --file methods 24 + 25 + Character Support: 26 + • Only US keyboard characters are supported via HID keycodes 27 + • Supported: A-Z, a-z, 0-9, and symbols: !@#$%^&*()_+-={}[]|\\:";'<>?,./`~ 28 + • Not supported: International characters (£€¥), accented letters (éñü), etc. 29 + • This is a limitation of the underlying HID keyboard protocol 30 + 31 + Note: iOS may apply smart punctuation spacing to some characters. 19 32 """ 20 33 ) 21 34 22 - @Option(name: .customShort("t"), help: "The text to type. Use single quotes for special characters.") 35 + @Argument(help: "The text to type. Use quotes for text with spaces or special characters.") 23 36 var text: String? 24 37 25 38 @Flag(name: .customLong("stdin"), help: "Read text from standard input.") ··· 40 53 // Determine input source and get text 41 54 let inputText: String 42 55 56 + // Check if we have multiple input sources 57 + let sourceCount = [text != nil, useStdin, inputFile != nil].filter { $0 }.count 58 + if sourceCount > 1 { 59 + throw ValidationError("Please specify only one input source: text argument, --stdin, or --file.") 60 + } 61 + 43 62 switch (text, useStdin, inputFile) { 44 - case (let directText?, false, nil): 45 - // Direct text input 46 - inputText = directText 47 - logger.info().log("Using direct text input: '\(inputText)'") 63 + case (let positionalText?, false, nil): 64 + // Positional argument 65 + inputText = positionalText 66 + logger.info().log("Using positional text input: '\(inputText)'") 48 67 49 68 case (nil, true, nil): 50 69 // Read from stdin ··· 60 79 61 80 case (nil, false, nil): 62 81 // No input provided 63 - throw ValidationError("No input provided. Use -t, --stdin, or --file.") 82 + throw ValidationError("No input provided. Provide text as argument, or use --stdin, or --file.") 64 83 65 84 default: 66 - // Multiple input sources provided 67 - throw ValidationError("Please specify only one input source: -t, --stdin, or --file.") 85 + // This shouldn't happen due to earlier check 86 + throw ValidationError("Invalid input configuration.") 68 87 } 69 88 70 89 // Validate text first ··· 74 93 let keyEvent = KeyEvent.keyCodeForString(String(char)) 75 94 return keyEvent.keyCode == 0 ? char : nil 76 95 } 77 - let errorMessage = "Unsupported characters found: \(unsupportedChars.map { "'\($0)'" }.joined(separator: ", "))" 96 + let errorMessage = """ 97 + Unsupported characters found: \(unsupportedChars.map { "'\($0)'" }.joined(separator: ", ")) 98 + 99 + Only US keyboard characters are supported via HID keycodes. 100 + Supported: A-Z, a-z, 0-9, and symbols: !@#$%^&*()_+-={}[]|\\:";'<>?,./`~ 101 + """ 78 102 logger.error().log(errorMessage) 79 103 throw TextToHIDEvents.TextConversionError.unsupportedCharacter(unsupportedChars.first!) 80 104 }