A command-line tool intended to insert a conditional compilation statement in multiple Swift files at once.
And generic enough being able to process multiple files and insert any text at the top and the bottom of a file :)
swift run conditional-files find .
swift run conditional-files find . | xargs swift run conditional-files remove
Set one or more respective flags, e.g. for iOS use --ios
.
Pass a single dot (.
) as argument to process all files in the current directory and subdirectories.
Example: swift run conditional-files --ios .
File (before) | File (after) |
import CarKey
// code |
#if os(iOS)
import CarKey
// code
#endif |
You can add multiple statements by adding multiple flags.
swift run conditional-files --ios --watchos .
File (before) | File (after) |
import CarKey
// code |
#if os(iOS) || os(watchOS)
import CarKey
// code
#endif |
You can remove an existing compiler directive with flag remove
.
swift run conditional-files --ios --undo test.swift
File (before) | File (after) |
#if os(iOS)
import CarKey
// code
#endif |
import CarKey
// code |
Pass one or more file paths as arguments.
swift run conditional-files --ios test.swift
File (before) | File (after) |
import CarKey
// code |
#if os(iOS)
import CarKey
// code
#endif |
You can negate the #if(os) directive with command not-os
.
swift run conditional-files not-os --ios --watchos test.swift
File (before) | File (after) |
import CarKey
// code |
#if !os(iOS) && !os(watchOS)
import CarKey
// code
#endif |
swift run conditional-files generic --first-line '#if DEBUG' --last-line \#endif test.swift
File (before) | File (after) |
import CarKey
// code |
#if DEBUG
import CarKey
// code
#endif |
You can also add any top & bottom lines.
swift run conditional-files generic --first-line BEGIN --last-line END test.swift
File (before) | File (after) |
|
|