Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework cobra CLI #41

Merged
merged 4 commits into from Aug 10, 2018
Merged

Rework cobra CLI #41

merged 4 commits into from Aug 10, 2018

Conversation

retr0h
Copy link
Collaborator

@retr0h retr0h commented Aug 9, 2018

  • Moved the CLI into cmd package.

  • Broke out each subcommand into own file.

  • Created a version subcommand, which allows the binary to be built
    with version information when passed the following LDFLAGS.

    LDFLAGS := -s -w
    -X 'main.version=$(VERSION)'
    -X 'main.buildHash=$(GITCOMMIT)'
    -X 'main.buildDate=$(BUILDDATE)'

* Moved the CLI into cmd package.
* Broke out each subcommand into own file.
* Created a version subcommand, which allows the binary to be built
  with version information when passed the following LDFLAGS.

    LDFLAGS := -s -w \
	-X 'main.version=$(VERSION)'
	-X 'main.buildHash=$(GITCOMMIT)'
	-X 'main.buildDate=$(BUILDDATE)'
@retr0h
Copy link
Collaborator Author

retr0h commented Aug 9, 2018

Also added a sexy command banner lol

          __
 .-----. |  |--. .--.--.--.
 |  _  | |     | |  |  |  |
 |___  | |__|__| |________|
 |_____|

Discover hardware information.

https://github.com/jaypipes/ghw

Usage:
  ghwc [flags]
  ghwc [command]

Available Commands:
  block       Show block storage information for the host system
  cpu         Show CPU information for the host system
  gpu         Show graphics/GPU information for the host system
  help        Help about any command
  memory      Show memory information for the host system
  net         Show network information for the host system
  topology    Show topology information for the host system
  version     Display the version of gofile

Flags:
      --debug   Enable or disable debug mode
  -h, --help    help for ghwc

Use "ghwc [command] --help" for more information about a command.

Since the CLI imports gcw the vendor/ directory should
live at the base of the repo.  This also brings the project
in line with most other go projects.  Updated Makefile and
gitignore to preserve functionality.
Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approving yet only due to the question about library vs. CLI tool dependencies (see inline)

cmd/root.go Outdated
.-----. | |--. .--.--.--.
| _ | | | | | | |
|___ | |__|__| |________|
|_____|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, this makes me think of someone giving someone else the middle finger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lolol

cmd/version.go Outdated
`

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I'd wanted to do something like this. Thanks for adding it! :)

@@ -21,5 +21,5 @@
"revisionTime": "2017-05-08T18:43:26Z"
}
],
"rootPath": "github.com/jaypipes/ghw/ghwc"
"rootPath": "github.com/jaypipes/ghw"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the reason I had the ghwc/vendor folder was that I did not want to make cobra a dependency for the ghw library itself. I wanted to have as few (or no) dependencies for the importable library as possible. Is there a way to indicate that the dependency is only for the ghwc example client tool and not the library itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I seee. Now I understand what ghwc was for.

This should allow the CLI to remain using vendored packages, while
keeping dependencies as minimal as possible with the importable
package.
Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastico. :)

@jaypipes jaypipes merged commit 1a19ac5 into jaypipes:master Aug 10, 2018
@retr0h retr0h deleted the rework-cobra-cli branch August 10, 2018 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants