Class: Renuo::CLI

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

Instance Method Summary collapse

Instance Method Details

#startObject



42
43
44
45
46
47
48
49
50
51
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/renuo/cli.rb', line 42

def start
  require "commander/import"
  program :version, Renuo::Cli::VERSION
  program :description, "Renuo CLI"

  info = Gems.info Renuo::Cli::NAME

  if Gem::Version.new(Renuo::Cli::VERSION) < Gem::Version.new(info["version"])
    say "You are running the version #{Renuo::Cli::VERSION} but the brand new #{info["version"]} is available. 🎉"
    if agree("Why don't you update with `gem update renuo-cli`? I can run it for you. 💪")
      system("gem update #{Renuo::Cli::NAME}")
      abort "Nice! I updated myself. 🤩 Now you can run the command again."
    end
    abort("Good. Just do it yourself then...😒")
  end

  command :"display-name" do |c|
    c.syntax = "renuo display-name [options]"
    c.summary = "Sets the name of a customer on the Renuo dashboard"
    c.description = "Sets the name of a customer on the Renuo dashboard"
    c.example 'Display "Peter Muster" on the dashboard', 'renuo display-name "Peter Muster"'
    c.example "Remove the current name from the dashboard", "renuo display-name --delete"
    c.example "Override the current message on the dashboard", "renuo display-name Happy friday 🍻 --override"
    c.option "--delete", "Deletes the current name"
    c.option "--override", "Overrides the entire message"
    c.option "--monitor", "Open the Google slides"
    c.action do |args, options|
      NameDisplay.new.run(args, options)
    end
  end

  command "list-large-git-files" do |c|
    c.syntax = "renuo list-large-git-files"
    c.summary = "Lists the 5 largest files in a git repository. Warning: must be a bare checkout of the repo!"
    c.description = "Lists the 5 largest files in a git repository.\nWarning: must be a bare checkout of the repo!"
    c.example "list the 5 largest git files of github.com/renuo/renuo-cli",
              "git clone --bare [email protected]:renuo/renuo-cli.git && " \
              "cd renuo-cli.git && renuo list-large-git-files"
    c.action do
      ListLargeGitFiles.new.run
    end
  end

  command "generate-password" do |c|
    c.syntax = "renuo generate-password"
    c.summary = "Generates a phrase of random 0-9a-zA-Z characters. Choose a substring of it as a new password."
    c.description = "Generates a phrase of random 0-9a-zA-Z characters. Choose a substring of it as a new password."
    c.example "renuo generate-password", "generates a random password"
    c.action do
      GeneratePassword.new.run
    end
  end

  command "upgrade-laptop" do |c|
    c.syntax = "renuo upgrade-laptop"
    c.summary = "Upgrades the installed apps from the app store, macOS and homebrew"
    c.description = "Upgrades the installed apps from the app store, macOS and homebrew"
    c.example "renuo upgrade-laptop", "upgrades your laptop"
    c.action do
      UpgradeLaptop.new.run
    end
  end

  command "create-new-logins" do |c|
    c.syntax = "renuo create-new-logins"
    c.summary = "Guides you through the sign up pages for Sentry, NewRelic and Gemnasium"
    c.description = "Guides you through the sign up pages for Sentry, NewRelic and Gemnasium"
    c.example "renuo create-new-logins", "creates new logins"
    c.action do
      CreateNewLogins.new.run
    end
  end

  command "create-aws-project" do |c|
    c.syntax = "renuo create-aws-project"
    c.summary = "Generates necessary commands for our project setup on AWS incl. necessary installations."
    c.description = <<~DESCRIPTION
      This creates commands for creating AWS users, buckets an versioning policies and CloudFront.
      It also guides you to set up the necessary environment.

      You will be asked for:
      (- installation of aws-cli, if not yet done)
      (- setting up aws user `renuo-app-setup`, if not yet done)
      - project name and suffix so that the script can respect our naming conventions
      - the Redmine project name to tag buckets for AWS billing references
      - whether you want to setup CloudFront to deliver assets via S3

      The generated commands do the following:
      - create an IAM user for each environment (main, develop) and add it to the renuo apps group.
      - create S3 buckets for each user who owns it
      - tag the buckets
      - enable versioning for main buckets
      (- set up a CloudFront distribution for each environment with the default config or plus alias if configured)
    DESCRIPTION
    c.example "Setup a project (you will be asked for details)", "renuo create-aws-project"
    c.action do |_args, _options|
      CreateAwsProject.new.run
    end
  end

  command "work" do |c|
    c.syntax = "renuo work"
    c.summary = "A utility command to start working on a ticket."
    c.description = "When you start working on a feature, it will jump to the project folder, " \
                    "start a new feature with the ticket number," \
                    'move the ticket in "In progress" state on Redmine and start Toggl with the ' \
                    "ticket number or add the ticket number to the running one if there was none."
    c.example "renuo work start kinova 1234", "start working on ticket 1234 on kinova project"
    c.action do |args|
      Work.new.run(args)
    end
  end

  command "release" do |c|
    c.syntax = "renuo release"
    c.summary = "Release a projects state of develop (on github) to main in one command."
    c.description = "Creates a new release version of a project on main as either a Major, Minor, " \
                    "Patch or Custom release based on the current state of develop on Github"
    c.example "renuo release my-project minor", "release a minor release of my-project"
    c.example "renuo release my-project custom 2.5.0", "release my-project as release 2.5.0"
    c.action do |args|
      ReleaseProject.new.run(args)
    end
  end

  command "create-heroku-app" do |c|
    c.syntax = "renuo create-heroku-app"
    c.summary = "Generates the script necessary to setup an application on Heroku."
    c.description = "Generates the script necessary to setup an application on Heroku."
    c.example "renuo create-heroku-app hello", "generates the command to create hello on Heroku"
    c.action do |args|
      CreateHerokuApp.new.run(args)
    end
  end

  command "configure-sentry" do |c|
    c.syntax = "renuo configure-sentry [project-name] [SENTRY_DSN]"
    c.summary = "Generates the script necessary to setup sentry on Heroku."
    c.description = c.summary
    c.example "renuo configure-sentry myproject https://[email protected]/11223344",
              "generates the command to configure sentry for myproject on Heroku"
    c.action do |args|
      ConfigureSentry.new.run(args)
    end
  end

  command "fetch-emails" do |c|
    c.syntax = "renuo fetch-emails"
    c.summary = "Retrieves all renuo employees email addresses"
    c.description = "Retrieves all renuo employees email addresses. One per line."
    c.action do |args|
      FetchEmails.new.run(args)
    end
  end

  command "heroku-users" do |c|
    c.syntax = "renuo heroku-users add/remove emailaddress"
    c.summary = "Prints a list of commands to add or remove an email address from all Heroku projects"
    c.description = "Useful when a new person is hired or a person quits."
    c.example "renuo heroku-users add [email protected]",
              "Adds the user [email protected] to all the Heroku projects"
    c.example "renuo heroku-users remove [email protected]",
              "Removes the user [email protected] from all the Heroku projects"
    c.action do |args|
      HerokuUsers.new.run(args)
    end
  end

  command "setup-uptimerobot" do |c|
    c.syntax = "renuo setup-uptimerobot"
    c.summary = "Sets up uptimerobot for the given project"
    c.description = "The uptimerobot configuration is mandatory for most projects. " \
                    "This command sets everything up and pauses the monitoring directly. Once the app is ready, " \
                    "the monitoring should get started."
    c.example "renuo setup-uptimerobot https://redmine.ch", "Configures redmine monitoring on uptimerobot"
    c.action do |args|
      SetupUptimerobot.new(args).run
    end
  end

  command "release-xing" do |c|
    c.syntax = "renuo release-xing"
    c.summary = "Release Xing to preview."
    c.description = "Xing needs to be released manually. " \
                    "You need a VPN connection open before runnign this command."
    c.action do |_args|
      ReleaseXing.new.run
    end
  end

  command "configure-semaphore" do |c|
    c.syntax = "renuo configure-semaphore"
    c.summary = "Adds standard semaphore configuration files to a project and creates the notifications"
    c.description = "Run this command with a project, to add the semaphore configuration files " \
                    "and create notifications."
    c.action do |_args|
      ConfigureSemaphore.new.call
    end
  end

  command "toggl-redmine" do |c|
    c.syntax = "renuo toggl-redmine"
    c.summary = "Compares your time entries between Toggl and Redmine"
    c.description = "This command extracts your time entries in Toggl and in Redmine and checks if they are " \
                    "consistant. It can help you in your time booking to find if you booked something wrong"
    c.action do |_args|
      TogglRedmineComparator.call
    end
  end

  command "create-slidev-presentation" do |c|
    c.syntax = "renuo create-slidev-presentation [presentation-name]"
    c.summary = "Creates a new Slidev presentation with the Renuo theme"
    c.description = "Creates a new Slidev presentation with the Renuo theme"
    c.action do |args|
      CreateSlidevPresentation.new.run(args)
    end
  end

  command "commit-leaderboard-stage" do |c|
    c.syntax = "renuo commit-leaderboard-stage [username] [avatar-url] [queue-path]"
    c.summary = "Adds local commits to a local queue for the commit leaderboard"
    c.option "--verbose", "Prints the latest commit"
    c.description = <<~DESCRIPTION
      Add post-commit hook to `git config core.hookspath` with the following contents:

      #!/usr/bin/env sh
      renuo commit-leaderboard-stage CuddlyBunion341 "https://avatars.githubusercontent.com/u/53896675?v=4" ~/.renuo-commit-leaderboard.json

      # You can get the GitHub avatar url using `gh api user | jq .avatar_url`
    DESCRIPTION

    c.action do |args, options|
      CommitLeaderboardStage.new.run(args, options)
    end
  end

  command "commit-leaderboard-sync" do |c|
    c.syntax = "renuo commit-leaderboard-sync [api-secret]  [queue-path] [api-url]"
    c.summary = "Sends commits from the queue to the commit leaderboard"
    c.description = <<~DESCRIPTION
      Sends commits from the queue to the commit leaderboard
      Add pre-push hook to `git config core.hookspath` with the following contents:

      #/usr/bin/env sh
      renuo commit-leaderboard-sync {SECRET} ~/.renuo-commit-leaderboard.json https://dashboard.renuo.ch/api/v1/commit_leaderboard
    DESCRIPTION
    c.option "--verbose", "Prints the configuration, request body and response"
    c.action do |args, options|
      CommitLeaderboardSync.new.run(args, options)
    end
  end

  command "fetch-secrets" do |c|
    c.syntax = "renuo fetch-secrets"
    c.summary = "Fetches the needed secrets in a project from the renuo secrets store"
    c.description = <<~DESCRIPTION
      Run the command within a project folder to fetch the secrets from the renuo secrets store.
      The bin/setup of the project might run this command for you.
    DESCRIPTION
    c.action do
      SecretsFetcher.new.run
    end
  end
end