From 6ca4e381671958ba7a09ec1d868b0d29f423160f Mon Sep 17 00:00:00 2001 From: "V. Elenhaupt" <3624712+veelenga@users.noreply.github.com> Date: Wed, 1 Nov 2017 17:21:41 +0200 Subject: [PATCH] Ameba cli & binary (#7) * Ameba cli & binary * -1 when ameba found issues * Add postscript to shard.yml * Correct postinstall * Remove targets * Try executables --- .gitignore | 2 +- .travis.yml | 3 +++ Makefile | 10 ++++++++++ bin/.keep | 0 shard.yml | 8 ++++++-- src/ameba.cr | 1 + src/cli.cr | 20 ++++++++++++++++++++ 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 bin/.keep create mode 100644 src/cli.cr diff --git a/.gitignore b/.gitignore index 23ec6569..7223105b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /doc/ /lib/ -/bin/ +/bin/ameba /.shards/ # Libraries don't need dependency lock diff --git a/.travis.yml b/.travis.yml index ffc7b6ac..40ce77c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,4 @@ language: crystal +after_script: + - make build + - ./bin/ameba diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..91efc969 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CRYSTAL_BIN ?= $(shell which crystal) +PREFIX ?= /usr/local + +build: + $(CRYSTAL_BIN) build --release --no-debug -o bin/ameba src/cli.cr $(CRFLAGS) +clean: + rm -f ./bin/ameba +install: build + mkdir -p $(PREFIX)/bin + cp ./bin/ameba $(PREFIX)/bin diff --git a/bin/.keep b/bin/.keep new file mode 100644 index 00000000..e69de29b diff --git a/shard.yml b/shard.yml index 27e79828..4fb9171f 100644 --- a/shard.yml +++ b/shard.yml @@ -1,9 +1,13 @@ name: ameba version: 0.1.0 +crystal: 0.23.1 +license: MIT authors: - Vitalii Elenhaupt -crystal: 0.23.1 +scripts: + postinstall: make build -license: MIT +executables: + - ameba diff --git a/src/ameba.cr b/src/ameba.cr index 043b4846..610a0360 100644 --- a/src/ameba.cr +++ b/src/ameba.cr @@ -23,6 +23,7 @@ module Ameba reporter.report source end reporter.try &.finish sources + sources end def catch(source : Source) diff --git a/src/cli.cr b/src/cli.cr new file mode 100644 index 00000000..3d3c7816 --- /dev/null +++ b/src/cli.cr @@ -0,0 +1,20 @@ +require "option_parser" +require "./ameba" + +OptionParser.parse(ARGV) do |parser| + parser.banner = "Usage: ameba [options]" + + parser.on("-v", "--version", "Print version") do + puts Ameba::VERSION + exit 0 + end + + parser.on("-h", "--help", "Show this help") do + puts parser + exit 0 + end +end + +sources = Ameba.run +failed = sources.any? { |s| !s.valid? } +exit(-1) if failed