-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/nothub/gorinth/api" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var host *string | ||
|
||
func init() { | ||
host = pingCmd.Flags().String("host", "api.modrinth.com", "Host address") | ||
|
||
rootCmd.AddCommand(pingCmd) | ||
} | ||
|
||
var pingCmd = &cobra.Command{ | ||
Use: "ping", | ||
Short: "Ping Labrinth instance", | ||
Long: `Connect to a Labrinth instance and display basic information.`, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
client := api.NewClient(host) | ||
|
||
info, err := client.LabrinthInfo() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
fmt.Println(info.About) | ||
fmt.Println(info.Name, info.Version) | ||
fmt.Println(info.Documentation) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
// global flags | ||
rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "Author name for copyright attribution") | ||
rootCmd.PersistentFlags().Bool("dumm", true, "Use dumm for dumm") | ||
|
||
// local flags | ||
rootCmd.Flags().BoolP("toggle", "t", false, "toggle message for toggle flag") | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "gorinth", | ||
Short: "Modrinth Modpack server deployment", | ||
Long: `A longer description that spans multiple lines and likely | ||
contains examples and usage of using your application. | ||
For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path" | ||
"runtime/debug" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print version infos", | ||
Long: `Extract and display the running binaries embedded version information.`, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
info, ok := debug.ReadBuildInfo() | ||
if ok { | ||
fmt.Println(path.Base(info.Main.Path), info.Main.Version) | ||
} else { | ||
log.Fatalln("Unable to extract build infos from running binary!") | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
module github.com/nothub/gorinth | ||
|
||
go 1.19 | ||
|
||
require github.com/spf13/cobra v1.5.0 | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= | ||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/nothub/gorinth/api" | ||
"log" | ||
"github.com/nothub/gorinth/cmd" | ||
) | ||
|
||
func main() { | ||
client := api.NewClient() | ||
info, err := client.LabrinthInfo() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
fmt.Println(info.About) | ||
fmt.Println(info.Name, info.Version) | ||
fmt.Println(info.Documentation) | ||
cmd.Execute() | ||
} |