Class: SashimiTanpopo::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/sashimi_tanpopo/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_exec_common_optionsObject



17
18
19
20
21
22
# File 'lib/sashimi_tanpopo/cli.rb', line 17

def self.define_exec_common_options
  option :target_dir, type: :string, aliases: "-d", desc: "Target directory. Default: current directory"
  option :params,     type: :hash, aliases: "-p", default: {}, desc: "Params passed to recipe file", repeatable: true
  option :dry_run,    type: :boolean, default: false, desc: "Whether to run dry run"
  option :color,      type: :boolean, default: true, desc: "Whether to colorize output"
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/sashimi_tanpopo/cli.rb', line 13

def self.exit_on_failure?
  true
end

.normalize_params(params) ⇒ Hash<Symbol,String>

Examples:

normalize_params({"k1"=>"v1", "k2"=>"v2"})
#=> {k1: "v1", k2: "v2"}

Parameters:

  • params (Hash<String, String>)

Returns:

  • (Hash<Symbol,String>)


132
133
134
# File 'lib/sashimi_tanpopo/cli.rb', line 132

def self.normalize_params(params)
  params.transform_keys(&:to_sym)
end

Instance Method Details

#github(*recipe_files) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sashimi_tanpopo/cli.rb', line 52

def github(*recipe_files)
  repository       = option_or_env!(option_name: :github_repository, env_name: "GITHUB_REPOSITORY")
  api_endpoint     = option_or_env!(option_name: :github_api_url,    env_name: "GITHUB_API_URL")
  access_token     = option_or_env!(option_name: :github_token,      env_name: "GITHUB_TOKEN")

  Provider::GitHub.new(
    recipe_paths:     recipe_files,
    target_dir:       options[:target_dir],
    params:           self.class.normalize_params(options[:params]),
    dry_run:          options[:dry_run],
    is_colored:       options[:color],
    git_username:     options[:git_user_name],
    git_email:        options[:git_email],
    commit_message:   options[:message],
    repository:       repository,
    api_endpoint:     api_endpoint,
    access_token:     access_token,
    pr_title:         options[:pr_title],
    pr_body:          options[:pr_body],
    pr_source_branch: options[:pr_source_branch],
    pr_target_branch: options[:pr_target_branch],
    pr_assignees:     options[:pr_assignees],
    pr_reviewers:     options[:pr_reviewers],
    pr_labels:        options[:pr_labels],
    is_draft_pr:      options[:pr_draft],
  ).perform
end

#gitlab(*recipe_files) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sashimi_tanpopo/cli.rb', line 97

def gitlab(*recipe_files)
  repository       = option_or_env!(option_name: :gitlab_project,   env_name: %w[GITLAB_PROJECT CI_PROJECT_PATH])
  api_endpoint     = option_or_env!(option_name: :gitlab_api_url,   env_name: %w[GITLAB_API_URL CI_API_V4_URL])
  access_token     = option_or_env!(option_name: :gitlab_token,     env_name: "GITLAB_TOKEN")

  Provider::GitLab.new(
    recipe_paths:     recipe_files,
    target_dir:       options[:target_dir],
    params:           self.class.normalize_params(options[:params]),
    dry_run:          options[:dry_run],
    is_colored:       options[:color],
    git_username:     options[:git_user_name],
    git_email:        options[:git_email],
    commit_message:   options[:message],
    repository:       repository,
    api_endpoint:     api_endpoint,
    access_token:     access_token,
    mr_title:         options[:mr_title],
    mr_body:          options[:mr_body],
    mr_source_branch: options[:mr_source_branch],
    mr_target_branch: options[:mr_target_branch],
    mr_assignees:     options[:mr_assignees],
    mr_reviewers:     options[:mr_reviewers],
    mr_labels:        options[:mr_labels],
    is_draft_mr:      options[:mr_draft],
    is_auto_merge:    options[:mr_auto_merge],
  ).perform
end

#local(*recipe_files) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/sashimi_tanpopo/cli.rb', line 26

def local(*recipe_files)
  Provider::Local.new(
    recipe_paths: recipe_files,
    target_dir:   options[:target_dir],
    params:       self.class.normalize_params(options[:params]),
    dry_run:      options[:dry_run],
    is_colored:   options[:color],
  ).perform
end

#versionObject



9
10
11
# File 'lib/sashimi_tanpopo/cli.rb', line 9

def version
  puts "sashimi_tanpopo v#{SashimiTanpopo::VERSION}"
end