Skip to content

ref: Separate main.go into a cli builder#49

Merged
Callisto13 merged 1 commit intomainfrom
refactor-cli-flags
Jun 27, 2022
Merged

ref: Separate main.go into a cli builder#49
Callisto13 merged 1 commit intomainfrom
refactor-cli-flags

Conversation

@Callisto13
Copy link
Copy Markdown
Member

@Callisto13 Callisto13 commented Jun 22, 2022

Closes #24
Closes #42

This commit looks fairly busy, but there is very little new logic.

I have broken up the huge main.go into individual command files under
pkg/command. New code can be found in pkg/flags, pkg/defaults and
pkg/config. 95% of the content of pkg/command is lifted straight
from what was originally in main.go, the only difference is how the
app is constructed.

Each command now loads flag values from the context into a Config object
which can be used by the command action. Each command action is a
function which will be individually unit tested. Previously we were
testing all the permutations in integration tests, which was just too
much of a pain to do. Now we should be able to use a mocked client.

There are a couple of other things that I would like to do:

  • Add tests around the action funcs
  • Have another layer between the actions and the client
  • Have a dialFunc which is passed into the action func. This will be
    helpful when we add TLS and auth so we don't have to repeat the set up
    of creds for each command ref: Move Dial into a separate package #52

But I am leaving that for now.

@Callisto13 Callisto13 changed the base branch from main to server-var June 22, 2022 16:04
@Callisto13 Callisto13 force-pushed the refactor-cli-flags branch from 6f83a24 to 8b93064 Compare June 22, 2022 16:06
@Callisto13 Callisto13 changed the title Refactor cli flags ref: Separate main.go into a cli builder Jun 22, 2022
@Callisto13 Callisto13 force-pushed the refactor-cli-flags branch 4 times, most recently from d719c32 to 10e340d Compare June 27, 2022 13:00
Base automatically changed from server-var to main June 27, 2022 13:33
@Callisto13 Callisto13 requested a review from m-rcd June 27, 2022 13:33
@Callisto13 Callisto13 force-pushed the refactor-cli-flags branch from 10e340d to a247d39 Compare June 27, 2022 13:44
This commit looks fairly busy, but there is very little new logic.

I have broken up the huge `main.go` into individual command files under
`pkg/command`. New code can be found in `pkg/flags`, `pkg/defaults` and
`pkg/config`. 95% of the content of `pkg/command` is lifted straight
from what was originally in `main.go`, the only difference is how the
app is constructed.

Each command now loads flag values from the context into a Config object
which can be used by the command action. Each command action is a
function which will be individually unit tested. Previously we were
testing all the permutations in integration tests, which was just too
much of a pain to do. Now we should be able to use a mocked client.

There are a couple of other things that I would like to do:
- Add tests around the action funcs
- Have another layer between the actions and the client
- Have a dialFunc which is passed into the action func. This will be
  helpful when we add TLS and auth so we don't have to repeat the set up
  of creds for each command

But I am leaving that for now.
@Callisto13 Callisto13 force-pushed the refactor-cli-flags branch from a247d39 to dfdd65b Compare June 27, 2022 13:46
@Callisto13 Callisto13 marked this pull request as ready for review June 27, 2022 13:47
@Callisto13 Callisto13 merged commit 671ab7b into main Jun 27, 2022
@Callisto13 Callisto13 deleted the refactor-cli-flags branch June 27, 2022 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bump to go 1.18 Refactor cli.App into separate commands

1 participant