Skip to content

Commit

Permalink
Merge pull request HazAT#35 from dcordero/commands_generator
Browse files Browse the repository at this point in the history
Refactor command builder to use FastlaneCore::CommanderGenerator
  • Loading branch information
HazAT authored Dec 8, 2016
2 parents 1925d2e + 25f6fed commit d919031
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 75 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ It's built to easily integrate with [fastlane](https://github.com/fastlane/fastl

![assets/icon175x175_alpha_light_badged.png](assets/icon175x175_alpha_light_badged.png?raw=1) ![assets/icon175x175_fitrack_alpha_light_badged.png](assets/icon175x175_fitrack_alpha_light_badged.png?raw=1)

badge --shield="1.2-2031-orange" --no_badge
badge --shield "1.2-2031-orange" --no_badge

![assets/icon175x175_shield_1.2-2031-orange.png](assets/icon175x175_shield_1.2-2031-orange.png?raw=1) ![assets/icon175x175_fitrack_shield_1.2-2031-orange.png](assets/icon175x175_fitrack_shield_1.2-2031-orange.png?raw=1)

badge --shield="1.2-2031-orange" --no_badge --shield_no_resize
badge --shield "1.2-2031-orange" --no_badge --shield_no_resize

![assets/icon175x175_shield_1.2-2031-orange-no-resize.png](assets/icon175x175_shield_1.2-2031-orange-no-resize.png?raw=1) ![assets/icon175x175_fitrack_shield_1.2-2031-orange-no-resize.png](assets/icon175x175_fitrack_shield_1.2-2031-orange-no-resize.png?raw=1)

badge --shield="Version-0.0.3-blue" --dark
badge --shield "Version-0.0.3-blue" --dark

![assets/icon175x175_shield_Version-0.0.3-blue.png](assets/icon175x175_shield_Version-0.0.3-blue.png?raw=1) ![assets/icon175x175_fitrack_shield_Version-0.0.3-blue.png](assets/icon175x175_fitrack_shield_Version-0.0.3-blue.png?raw=1)

badge --shield="Version-0.0.3-blue" --dark --shield_no_resize
badge --shield "Version-0.0.3-blue" --dark --shield_no_resize

![assets/icon175x175_shield_Version-0.0.3-blue-no-resize.png](assets/icon175x175_shield_Version-0.0.3-blue-no-resize.png?raw=1) ![assets/icon175x175_fitrack_shield_Version-0.0.3-blue-no-resize.png](assets/icon175x175_fitrack_shield_Version-0.0.3-blue-no-resize.png?raw=1)
# Installation
Expand All @@ -50,14 +50,14 @@ Install the gem

# Usage

Call ```badge``` in your iOS projects root folder
Call ```badge``` in your projects root folder

badge

It will search all subfolders for your asset catalog app icon set and add the badge to the icons.

But you can also run badge on your Android or tvOS icons.
You have to use the `--glob="/**/*.appiconset/*.{png,PNG}"` parameter to adjust where to find your icons.
You have to use the `--glob "/**/*.appiconset/*.{png,PNG}"` parameter to adjust where to find your icons.

The keep the alpha channel in the icons use `--alpha_channel`

Expand All @@ -69,21 +69,21 @@ Here is the dark option (also available in combination with ```--alpha```):

You can also use your custom overlay/badge image

badge --custom="path_to/custom_badge.png"
badge --custom "path_to/custom_badge.png"

Add a shield at the top of your icon for all possibilites head over to: [shields.io](http://shields.io/). You just have to add the string of shield (copied from the URL)

badge --shield="Version-0.0.3-blue"
badge --shield "Version-0.0.3-blue"

Sometimes the response from shield.io takes a long time and can timeout. You can adjust the timeout to shield.io with `--shield_io_timeout=10` accordingly.
Sometimes the response from shield.io takes a long time and can timeout. You can adjust the timeout to shield.io with `--shield_io_timeout t 10` accordingly.

`--shield_gravity=North` changes the postion of the shield on the icon. Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.
`--shield_gravity North` changes the postion of the shield on the icon. Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.

In version [0.4.0](https://github.com/HazAT/badge/releases/tag/0.4.0) the default behavior of the shield graphic has been changed. The shield graphic will always be resized to **aspect fill** the icon instead of just adding the shield on the icon. The disable to new behaviour use `--shield_no_resize` which now only puts the shield on the icon again.

Add ```--no_badge``` as an option to hide the beta badge completely if you just want to add a shield.

Use `badge existing_project --help` to get list all possible parameters.
Use `badge --help` to get list all possible parameters.

# Usage with fastlane

Expand Down
63 changes: 2 additions & 61 deletions bin/badge
Original file line number Diff line number Diff line change
@@ -1,66 +1,7 @@
#!/usr/bin/env ruby

$:.push File.expand_path("../../lib", __FILE__)

require 'badge'
require 'commander'

HighLine.track_eof = false

class BadgeApplication
include Commander::Methods

def run
program :version, Badge::VERSION
program :description, 'Add a badge to your ios app icon'
program :help, 'Author', 'Daniel Griesser <[email protected]>'
program :help, 'Website', 'https://github.com/HazAT/badge'
program :help, 'GitHub', 'https://github.com/HazAT/badge'
program :help_formatter, :compact

global_option('--verbose', 'Shows a more verbose output') { $verbose = true }

always_trace!

default_command :existing_project

command :existing_project do |c|
c.syntax = 'badge'
c.description = "Adds a badge to your ios app icon"
c.option '--dark', 'Adds a dark badge instead of the white'
c.option '--alpha', 'Uses the word alpha instead of beta'
c.option '--alpha_channel', 'Keeps/Adds an alpha channel to the icons'
c.option '--custom STRING', String, 'Overlay a custom image on your icon'
c.option '--no_badge', 'Removes the beta badge'
c.option '--badge_gravity STRING', String, 'Position of the badge on icon. Default: SouthEast - Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.'
c.option '--shield STRING', String, 'Overlay a shield from shield.io on your icon, eg: Version-1.2-green'
c.option '--shield_io_timeout INTEGER', Integer, 'The timeout in seconds we should wait the get a response from shield.io'
c.option '--shield_gravity STRING', String, 'Position of shield on icon. Default: North - Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.'
c.option '--shield_no_resize', 'Shield image will no longer be resized to aspect fill the full icon. Instead it will only be shrinked to not exceed the icon graphic.'
c.option '--glob STRING', String, 'Glob pattern for finding image files Default: CURRENT_PATH/**/*.appiconset/*.{png,PNG}'

c.action do |args, options|
params = {}
params[:dark] = options.dark
params[:custom] = options.custom
params[:no_badge] = options.no_badge
params[:badge_gravity] = options.badge_gravity
params[:shield] = options.shield
params[:shield_gravity] = options.shield_gravity
params[:shield_no_resize] = options.shield_no_resize
params[:shield_io_timeout] = options.shield_io_timeout
params[:alpha] = options.alpha
params[:glob] = options.glob
params[:alpha_channel] = options.alpha_channel
Badge::Runner.new.run('.', params)
end
end

run!
end
end

require 'badge/commands_generator'

begin
BadgeApplication.new.run
end
Badge::CommandsGenerator.start
5 changes: 3 additions & 2 deletions lib/badge.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'badge/base'
require 'badge/runner'
#
require 'badge/options.rb'

require 'fastlane_core'
#

module Badge
UI = FastlaneCore::UI
end
2 changes: 1 addition & 1 deletion lib/badge/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Badge

VERSION = "0.5.1"
DESCRIPTION = "Add a badge overlay to your ios app icon"
DESCRIPTION = "Add a badge overlay to your app icon"

def self.root
File.dirname __dir__ + "/../../../"
Expand Down
42 changes: 42 additions & 0 deletions lib/badge/commands_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'commander'

HighLine.track_eof = false

module Badge
class CommandsGenerator

include Commander::Methods

def self.start
self.new.run
end

def run
program :version, Badge::VERSION
program :description, 'Add a badge to your app icon'
program :help, 'Author', 'Daniel Griesser <[email protected]>'
program :help, 'Website', 'https://github.com/HazAT/badge'
program :help, 'GitHub', 'https://github.com/HazAT/badge'
program :help_formatter, :compact

global_option('--verbose', 'Shows a more verbose output') { $verbose = true }

always_trace!

FastlaneCore::CommanderGenerator.new.generate(Badge::Options.available_options)

command :run do |c|
c.syntax = 'badge'
c.description = "Adds a badge to your app icon"

c.action do |args, options|
params = FastlaneCore::Configuration.create(Badge::Options.available_options, options.__hash__)
Badge::Runner.new.run('.', params)
end
end

default_command :run
run!
end
end
end
61 changes: 61 additions & 0 deletions lib/badge/options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'fastlane_core'

module Badge
class Options
def self.available_options

[
FastlaneCore::ConfigItem.new(key: :dark,
description: "Adds a dark badge instead of the white",
is_string: false,
optional: true),

FastlaneCore::ConfigItem.new(key: :alpha,
description: "Uses the work alpha instead of beta",
is_string: false,
optional: true),

FastlaneCore::ConfigItem.new(key: :alpha_channel,
description: "Keeps/Adds an alpha channel to the icons",
is_string: false,
optional: true),

FastlaneCore::ConfigItem.new(key: :custom,
description: "Overlay a custom image on your icon",
optional: true),

FastlaneCore::ConfigItem.new(key: :no_badge,
description: "Removes the beta badge",
is_string: false,
optional: true),

FastlaneCore::ConfigItem.new(key: :badge_gravity,
description: "Position of the badge on icon. Default: SouthEast - Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast",
optional: true),

FastlaneCore::ConfigItem.new(key: :shield,
description: "Overlay a shield from shield.io on your icon, eg: Version-1.2-green",
optional: true),

FastlaneCore::ConfigItem.new(key: :shield_io_timeout,
description: "The timeout in seconds we should wait the get a response from shield.io",
type: Integer,
optional: true),

FastlaneCore::ConfigItem.new(key: :shield_gravity,
description: "Position of shield on icon. Default: North - Choices include: NorthWest, North, NorthEast, West, Center, East, South, West, South, SouthEast",
optional: true),

FastlaneCore::ConfigItem.new(key: :shield_no_resize,
description: "Shield image will no longer be resized to aspect fill the full icon. Instead it will only be shrinked to not exceed the icon graphic",
is_string: false,
optional: true),

FastlaneCore::ConfigItem.new(key: :glob,
description: "Glob pattern for finding image files Default: CURRENT_PATH/**/*.appiconset/*.{png,PNG}",
optional: true)
]
end
end
end

0 comments on commit d919031

Please sign in to comment.