Skip to content

Commit

Permalink
Move pgcenter.go into cmd package.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Jan 31, 2021
1 parent 3ca2f12 commit e1e18eb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
PROGRAM_NAME = pgcenter

SOURCE = ${PROGRAM_NAME}.go
COMMIT=$(shell git rev-parse --short HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG=$(shell git describe --tags |cut -d- -f1)

LDFLAGS = -ldflags "-X github.com/lesovsky/pgcenter/cmd.gitTag=${TAG} \
-X github.com/lesovsky/pgcenter/cmd.gitCommit=${COMMIT} \
-X github.com/lesovsky/pgcenter/cmd.gitBranch=${BRANCH}"
LDFLAGS = -ldflags "-X main.gitTag=${TAG} -X main.gitCommit=${COMMIT} -X main.gitBranch=${BRANCH}"

.PHONY: help clean dep build install uninstall

Expand Down Expand Up @@ -35,11 +32,7 @@ test: dep ## Run tests

build: dep ## Build pgcenter executable.
mkdir -p ./bin
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o bin/${PROGRAM_NAME} ${SOURCE}

build-debug: dep ## Build pgcenter executable.
mkdir -p ./bin
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -gcflags="all=-N -l" -o bin/${PROGRAM_NAME} ${SOURCE}
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o bin/${PROGRAM_NAME} ./cmd

install: ## Install pgcenter executable into /usr/bin directory.
install -pm 755 bin/${PROGRAM_NAME} /usr/bin/${PROGRAM_NAME}
Expand Down
4 changes: 2 additions & 2 deletions cmd/help.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Help templates

package cmd
package main

import (
"fmt"
Expand Down Expand Up @@ -33,7 +33,7 @@ Use "pgcenter [command] --help" for more information about a command.
Report bugs to <%s>.
`,
Root.Long,
pgcenter.Long,
config.CommandDefinition.Short,
profile.CommandDefinition.Short,
record.CommandDefinition.Short,
Expand Down
33 changes: 19 additions & 14 deletions cmd/cmd.go → cmd/pgcenter.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Entry point for root command - pgcenter

package cmd
package main

import (
"fmt"
"github.com/lesovsky/pgcenter/cmd/config"
"github.com/lesovsky/pgcenter/cmd/profile"
"github.com/lesovsky/pgcenter/cmd/record"
Expand All @@ -11,50 +10,56 @@ import (
"github.com/spf13/cobra"
)

// Root describes the CLI command of main program
var Root = &cobra.Command{
// pgcenter describes the root command of program
var pgcenter = &cobra.Command{
Use: programName,
Short: "Admin tool for PostgreSQL",
Long: "pgCenter is a command line admin tool for PostgreSQL.",
SilenceUsage: true,
SilenceErrors: true,
Version: printVersion(), // use constants from version.go
Version: printVersion(),
}

func init() {
Root.PersistentFlags().BoolP("help", "?", false, "show this help and exit")
pgcenter.PersistentFlags().BoolP("help", "?", false, "show this help and exit")

// Setup help and versions templates for main program
Root.SetVersionTemplate(printVersion())
Root.SetHelpTemplate(printMainHelp())
pgcenter.SetVersionTemplate(printVersion())
pgcenter.SetHelpTemplate(printMainHelp())

// Setup 'config' sub-command
Root.AddCommand(config.CommandDefinition)
pgcenter.AddCommand(config.CommandDefinition)
config.CommandDefinition.SetVersionTemplate(printVersion())
config.CommandDefinition.SetHelpTemplate(printConfigHelp())
config.CommandDefinition.SetUsageTemplate(printConfigHelp())

// Setup 'profile' sub-command
Root.AddCommand(profile.CommandDefinition)
pgcenter.AddCommand(profile.CommandDefinition)
profile.CommandDefinition.SetVersionTemplate(printVersion())
profile.CommandDefinition.SetHelpTemplate(printProfileHelp())
profile.CommandDefinition.SetUsageTemplate(printProfileHelp())

// Setup 'record' sub-command
Root.AddCommand(record.CommandDefinition)
pgcenter.AddCommand(record.CommandDefinition)
record.CommandDefinition.SetVersionTemplate(printVersion())
record.CommandDefinition.SetHelpTemplate(printRecordHelp())
record.CommandDefinition.SetUsageTemplate(printRecordHelp())

// Setup 'report' sub-command
Root.AddCommand(report.CommandDefinition)
pgcenter.AddCommand(report.CommandDefinition)
report.CommandDefinition.SetVersionTemplate(printVersion())
report.CommandDefinition.SetHelpTemplate(printReportHelp())
report.CommandDefinition.SetUsageTemplate(printReportHelp())

// Setup 'top' sub-command
Root.AddCommand(top.CommandDefinition)
pgcenter.AddCommand(top.CommandDefinition)
top.CommandDefinition.SetVersionTemplate(printVersion())
top.CommandDefinition.SetHelpTemplate(printTopHelp())
top.CommandDefinition.SetUsageTemplate(printTopHelp())
}

func main() {
if err := pgcenter.Execute(); err != nil {
fmt.Println(err)
}
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Stuff related to program versions, releases, etc.

package cmd
package main

import (
"fmt"
Expand Down
12 changes: 0 additions & 12 deletions pgcenter.go

This file was deleted.

0 comments on commit e1e18eb

Please sign in to comment.