Skip to content

Commit

Permalink
CLI: Simplify the options preparation for each command
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Jan 27, 2022
1 parent 334e646 commit dc5ee08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-10-18 17:37:42 UTC using RuboCop version 1.22.1.
# on 2022-01-27 22:01:02 UTC using RuboCop version 1.24.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 9
# Offense count: 10
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 60

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 174
Max: 175

# Offense count: 4
# Offense count: 5
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 14
Expand All @@ -26,7 +26,7 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Max: 34

# Offense count: 3
# Offense count: 4
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 15
Expand Down
35 changes: 7 additions & 28 deletions lib/modulesync/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ class Hook < Thor
:default => CLI.defaults[:branch]
desc 'activate', 'Activate the git hook.'
def activate
config = { :command => 'hook' }.merge(options)
config[:hook] = 'activate'
ModuleSync.hook(config)
ModuleSync.hook prepare_options(options, hook: 'activate')
end

desc 'deactivate', 'Deactivate the git hook.'
def deactivate
config = { :command => 'hook' }.merge(options)
config[:hook] = 'deactivate'
ModuleSync.hook(config)
ModuleSync.hook prepare_options(options, hook: 'deactivate')
end
end

Expand Down Expand Up @@ -136,16 +132,13 @@ class Base < Thor
:desc => 'Branch name to make the changes in.' \
' Defaults to the default branch of the upstream repository, but falls back to "master".',
:default => CLI.defaults[:branch]

def update
config = { :command => 'update' }.merge(options)
config = Util.symbolize_keys(config)
options = prepare_options(options)
raise Thor::Error, 'No value provided for required option "--message"' unless config[:noop] \
|| config[:message] \
|| config[:offline]

config[:git_opts] = { 'amend' => config[:amend], 'force' => config[:force] }
ModuleSync.update(config)
ModuleSync.update options
end

desc 'execute [OPTIONS] -- COMMAND..', 'Execute the command in each managed modules'
Expand Down Expand Up @@ -184,13 +177,8 @@ def execute(*command_args)
:default => false
option :source_branch,
:desc => 'Branch to reset from (e.g. origin/wip)'

def reset
config = {
:command => 'reset',
}.merge(options)
config = Util.symbolize_keys(config)
ModuleSync.reset(config)
ModuleSync.reset prepare_options(options)
end

desc 'push', 'Push all available commits from branch to remote'
Expand All @@ -206,22 +194,13 @@ def reset
:default => CLI.defaults[:branch]
option :remote_branch,
:desc => 'Remote branch to push to (e.g. maintenance)'

def push
config = {
:command => 'push',
}.merge(options)
config = Util.symbolize_keys(config)
ModuleSync.push(config)
ModuleSync.push prepare_options(options)
end

desc 'clone', 'Clone repositories that need to'
def clone
config = {
:command => 'clone',
}.merge(options)
config = Util.symbolize_keys(config)
ModuleSync.clone(config)
ModuleSync.clone prepare_options(options)
end

desc 'hook', 'Activate or deactivate a git hook.'
Expand Down

0 comments on commit dc5ee08

Please sign in to comment.