Swiftpack.co - Kyome22/LineCounter as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Kyome22.
Kyome22/LineCounter 1.0.0
指定したファイルの行数を数えるCommand Line Tool
⭐️ 3
🕓 2 years ago
macOS
.package(url: "https://github.com/Kyome22/LineCounter.git", from: "1.0.0")

LineCounter

LineCounter は指定したファイルまたはディレクトリ内のファイルの行数を数える Command Line Tool です。

インストール方法

$ git clone [email protected]:Kyome22/LineCounter.git
$ swift build -c release
$ cp .build/release/lc /usr/local/bin/lc

使い方

$ lc --help

でコマンドの使い方が出力されます。

$ lc -p [対象のパス]

とすれば、ファイルの場合はその行数を、ディレクトリの場合はそのディレクトリに含まれるファイルを再起的に探索してそれぞれの行数を出力します。

複数のパスを指定したい場合は、

$ lc -p [対象のパス] -p [対象のパス] -p [対象のパス]

のようにパスごとに引数を指定すればよいです。

また、

$ lc -p [対象のパス] -e [拡張子]

とすれば、行数をカウントするファイルの種類を指定できます。

--no-warnings フラグを付ければ、行数のカウントをスキップしたファイルや読み込み不可なファイルのログを省略できます。

プロジェクトへの導入方法

  1. Swift Pacakge Manager で LineCounter を Add します。

    Add Package
  2. Target 内では使用しないため、Choose Package Products for LineCounter はチェックをつけずにスルーします。

    Not Choose Package
  3. Target の Build Phase に Run Script を追加します。

    Add Run Script
    # プロジェクトのルートディレクトリ以下のSwiftファイルの行数をカウントする
    xcrun --sdk macosx swift run \
    --package-path ${BUILD_DIR%Build/*}SourcePackages/checkouts/LineCounter \
    lc -p ./${SRCROOT} -e swift --no-warnings
    

これで Build するたびに行数のカウントが実行されます。

Sample Output

GitHub

link
Stars: 3
Last commit: 47 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.0 (2022-03-12)
2 years ago

Version 1.0.0 released 🎉

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics