-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ws command line interface. (#23)
* Add ws command for Wordsmith command line interface. * Add alpine assets builder. * Remove misusage OptionParser missing_options * Fix PKG_NAME * Add ws pipe examples * Update ws usage in README.md * Refactor use STDIN.info.type.pipe? to check pipe * Update README.md Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com> * Update README.md Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com> * Update src/ws.cr Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com> * Fix bugs in alpline assets workflow * Try improve banner usage for ws * Bump version to 0.3.2 * Add workflow for build GNU X86_64 static binary * Add workflow for build static binary for Apple Darwin. * Update .github/workflows/apple_darwin_release.yml Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com> * Revert version changes and add authors in shard.yml Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com>
- Loading branch information
Showing
8 changed files
with
265 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: crystallang/crystal:latest-alpine | ||
steps: | ||
- name: Cache shards | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/shards | ||
key: ${{ runner.os }}-shards-${{ hashFiles('shard.yml') }} | ||
restore-keys: ${{ runner.os }}-shards- | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install shards | ||
run: shards check || shards install | ||
- name: Check formatting | ||
run: crystal tool format --check | ||
- name: Run tests | ||
run: crystal spec --order=random --error-on-warnings | ||
- name: package information | ||
run: | | ||
echo "BINARY_NAME=ws" >> $GITHUB_ENV | ||
echo "PKG_ARCH=x86_64" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: release binary | ||
id: release | ||
run: | | ||
shards build --production --release --progress --static --no-debug --link-flags="-s -Wl,-z,relro,-z,now" | ||
ASSERT_NAME=${BINARY_NAME}-${RELEASE_VERSION}-${PKG_ARCH}-unknown-linux-musl.tar.gz | ||
tar zcf ${ASSERT_NAME} bin/${BINARY_NAME} LICENSE | ||
echo ::set-output name=ASSERT_NAME::${ASSERT_NAME} | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: | | ||
${{ steps.release.outputs.ASSERT_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Cache shards | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/shards | ||
key: ${{ runner.os }}-shards-${{ hashFiles('shard.yml') }} | ||
restore-keys: ${{ runner.os }}-shards- | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
- name: Install shards | ||
run: shards check || shards install | ||
- name: Check formatting | ||
run: crystal tool format --check | ||
- name: Run tests | ||
run: crystal spec --order=random --error-on-warnings | ||
- name: package information | ||
run: | | ||
echo "BINARY_NAME=ws" >> $GITHUB_ENV | ||
echo "PKG_ARCH=x86_64" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: release binary | ||
id: release | ||
run: | | ||
shards build --production --release --progress --no-debug | ||
ASSERT_NAME=${BINARY_NAME}-${RELEASE_VERSION}-${PKG_ARCH}-apple-darwin.tar.gz | ||
tar zcf ${ASSERT_NAME} bin/${BINARY_NAME} LICENSE | ||
echo ::set-output name=ASSERT_NAME::${ASSERT_NAME} | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: | | ||
${{ steps.release.outputs.ASSERT_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cache shards | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/shards | ||
key: ${{ runner.os }}-shards-${{ hashFiles('shard.yml') }} | ||
restore-keys: ${{ runner.os }}-shards- | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
- name: Install shards | ||
run: shards check || shards install | ||
- name: Check formatting | ||
run: crystal tool format --check | ||
- name: Run tests | ||
run: crystal spec --order=random --error-on-warnings | ||
- name: package information | ||
run: | | ||
echo "BINARY_NAME=ws" >> $GITHUB_ENV | ||
echo "PKG_ARCH=x86_64" >> $GITHUB_ENV | ||
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: release binary | ||
id: release | ||
run: | | ||
shards build --production --release --progress --static --no-debug --link-flags="-s -Wl,-z,relro,-z,now" | ||
ASSERT_NAME=${BINARY_NAME}-${RELEASE_VERSION}-${PKG_ARCH}-unknown-linux-gnu.tar.gz | ||
tar zcf ${ASSERT_NAME} bin/${BINARY_NAME} LICENSE | ||
echo ::set-output name=ASSERT_NAME::${ASSERT_NAME} | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: | | ||
${{ steps.release.outputs.ASSERT_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
require "option_parser" | ||
require "colorize" | ||
require "./wordsmith" | ||
|
||
if STDIN.info.type.pipe? | ||
ARGV << STDIN.gets.not_nil! | ||
else | ||
ARGV << "--help" if ARGV.empty? | ||
end | ||
|
||
OptionParser.parse do |parser| | ||
parser.banner = <<-USAGE | ||
Usage: ws <option> WORD | ||
Wordsmith is a library for pluralizing, singularizing and doing | ||
other fun and useful things with words. | ||
Command `ws` is the command line version of Wordsmith, not all | ||
features of Wordsmith are implemented, for precompiled binary, | ||
please download from github releases page. | ||
https://github.com/luckyframework/wordsmith/releases | ||
some examples: | ||
$: #{"ws -s people".colorize(:light_yellow)} # => person | ||
$: #{"ws -p person".colorize(:light_yellow)} # => people | ||
You can use it with pipe: | ||
$: #{"echo \"WordSmith\" |ws -u |ws -d".colorize(:light_yellow)} # => word-smith | ||
more examples, please check https://github.com/luckyframework/wordsmith#usage | ||
USAGE | ||
|
||
parser.on( | ||
"-s WORD", | ||
"--singularize=WORD", | ||
"Return the singular version of the word." | ||
) do |word| | ||
puts Wordsmith::Inflector.singularize(word) | ||
end | ||
|
||
parser.on( | ||
"-p WORD", | ||
"--pluralize=WORD", | ||
"Return the plural version of the word." | ||
) do |word| | ||
puts Wordsmith::Inflector.pluralize(word) | ||
end | ||
|
||
parser.on( | ||
"-c WORD", | ||
"--camelize=WORD", | ||
"Return the camel-case version of that word." | ||
) do |word| | ||
puts Wordsmith::Inflector.camelize(word) | ||
end | ||
|
||
parser.on( | ||
"-C WORD", | ||
"--camelize-downcase=WORD", | ||
"Return the camel-case version of that word, but the first letter not capitalized." | ||
) do |word| | ||
puts Wordsmith::Inflector.camelize(word) | ||
end | ||
|
||
parser.on( | ||
"-u WORD", | ||
"--underscore=WORD", | ||
"Convert a given camel-case word to it's underscored version." | ||
) do |word| | ||
puts Wordsmith::Inflector.underscore(word) | ||
end | ||
|
||
parser.on( | ||
"-d WORD", | ||
"--dasherize=WORD", | ||
"Convert a given underscore-separated word to the same word, separated by dashes." | ||
) do |word| | ||
puts Wordsmith::Inflector.dasherize(word) | ||
end | ||
|
||
parser.on("-h", "--help", "Show this help") do | ||
puts parser | ||
exit | ||
end | ||
|
||
parser.invalid_option do |flag| | ||
STDERR.puts "ERROR: #{flag} is not a valid option.\n\n" | ||
STDERR.puts parser | ||
exit 1 | ||
end | ||
end |