Adding cobra root cli to application
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

drew/better-cli
Drew Bednar 6 months ago
parent 688c6083a5
commit 041965ad4f

1
.gitignore vendored

@ -24,5 +24,6 @@ go.work
# Flux Feed
fluxfeed
flux-feed
fluxctl
.env
flux-local.db

@ -15,11 +15,11 @@ vet: fmt
.PHONY:vet
build: vet
go build -o ./fluxfeed .
go build -o ./fluxctl .
.PHONY:build
clean:
rm -rf ./fluxfeed
rm -rf ./fluxctl
.PHONY:clean
docs:

@ -1,5 +1,25 @@
# Flux Feed
![build-status](https://drone.runcible.io/api/badges/androiddrew/flux-feed/status.svg)
[![](https://img.shields.io/badge/License-AGPL-blue.svg)](https://opensource.org/licenses/AGPL "License: AGPL")
An Indie Reader for the modern day.
An Indie Reader for the modern day.
## Building
From the root of the source tree run:
```shell
make build
```
## Using
```shell
./fluxctl --help
```
## License
is project is licensed under the MIT License. See the [LICENSE file](https://git.runcible.io/androiddrew/flux-feed/src/branch/main/LICENSE) for the full license text.

@ -1,5 +1,5 @@
// Entry point for applying database migrations for flux-feed application
package main
// Package cmd migrate provides a database migration command to root cli
package cmd
import (
"database/sql"
@ -8,11 +8,12 @@ import (
"git.runcible.io/androiddrew/flux-feed/config"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/mattn/go-sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file" //migrations
_ "github.com/mattn/go-sqlite3" //migrations
"github.com/spf13/cobra"
)
func main() {
func runMigrate(_ *cobra.Command, _ []string) {
cfg := config.New()
db, err := sql.Open(cfg.DatabaseDriver, cfg.DatabaseDSN)
defer db.Close()
@ -38,3 +39,10 @@ func main() {
log.Fatal(err)
}
}
// MigrateCmd provides database migrations command for cli
var MigrateCmd = &cobra.Command{
Use: "migrate",
Short: "Run database migrations",
Run: runMigrate,
}

@ -0,0 +1,26 @@
// Package cmd provides cli commands
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "fluxctl",
Short: "A flexible indie reader for the modern day",
}
// Execute executes the root command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func init() {
rootCmd.AddCommand(MigrateCmd)
}

@ -0,0 +1,10 @@
// Flux Feed main entrypoint
package main
import (
"git.runcible.io/androiddrew/flux-feed/cmd"
)
func main() {
cmd.Execute()
}
Loading…
Cancel
Save