Skip to content

CLI tool to mass insert/delete conditional compilation statements

License

Notifications You must be signed in to change notification settings

MarcoEidinger/conditional-files

Repository files navigation

Swift codecov

ConditionalFiles

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 :)

Find files with compiler directive (#if ... #endif) hugging the file content

swift run conditional-files find .

Find and remove hugging compilerdirective

swift run conditional-files find . | xargs swift run conditional-files remove

Add #if os() ... #endif to all files in (sub) directory

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

Remove #if os() ... #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

Add #if os() ... #endif to specific file(s)

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

Add #if !os() ... #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

Add #if DEBUG ... #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

Add any (generic) top & bottom line

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)
// text
BEGIN
// text
END

About

CLI tool to mass insert/delete conditional compilation statements

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages