forked from HazAT/badge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request HazAT#35 from dcordero/commands_generator
Refactor command builder to use FastlaneCore::CommanderGenerator
- Loading branch information
Showing
6 changed files
with
120 additions
and
75 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
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
require 'badge/base' | ||
require 'badge/runner' | ||
# | ||
require 'badge/options.rb' | ||
|
||
require 'fastlane_core' | ||
# | ||
|
||
module Badge | ||
UI = FastlaneCore::UI | ||
end |
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,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 |
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,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 | ||
|