Skip to content

Commit

Permalink
Merge pull request #136 from hofstadter-io/mod-revamp
Browse files Browse the repository at this point in the history
hof/mod: rewrite to focus on CUE
  • Loading branch information
verdverm authored Feb 22, 2023
2 parents 2b46a9b + 4dbd676 commit ff02b5c
Show file tree
Hide file tree
Showing 82 changed files with 3,331 additions and 1,170 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/hof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
fail-fast: false
matrix:
go:
- 1.18.x
- 1.19.x
- 1.20.x
os:
Expand Down Expand Up @@ -68,13 +67,16 @@ jobs:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: |-
# fetch CUE deps
hof mod vendor cue
# generate templates
# self: gen -> diff
set -e
# mods stuff & gen
hof mod tidy
hof mod vendor
hof gen
# should have no diff
git diff
# git diff --exit-code
git diff --exit-code
- name: Start formatters
run: |-
hof fmt start
Expand Down
28 changes: 6 additions & 22 deletions .hof/shadow/cli/cmd/hof/cmd/mod.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/lib/mod"

"github.com/hofstadter-io/hof/cmd/hof/cmd/mod"

"github.com/hofstadter-io/hof/cmd/hof/flags"

"github.com/hofstadter-io/hof/cmd/hof/ga"
)

Expand Down Expand Up @@ -119,11 +116,9 @@ See the ./lib/mod/langs in the repository for examples.
- We need a module system for our [hof-lang](https://hof-lang.org) project.
`

func ModPersistentPreRun(args []string) (err error) {

mod.InitLangs()
func init() {

return err
ModCmd.PersistentFlags().BoolVarP(&(flags.ModPflags.Update), "update", "u", false, "update dependencies while processing")
}

var ModCmd = &cobra.Command{
Expand All @@ -138,18 +133,6 @@ var ModCmd = &cobra.Command{

Long: modLong,

PersistentPreRun: func(cmd *cobra.Command, args []string) {
var err error

// Argument Parsing

err = ModPersistentPreRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},

PreRun: func(cmd *cobra.Command, args []string) {

ga.SendCommandPath(cmd.CommandPath())
Expand Down Expand Up @@ -189,8 +172,9 @@ func init() {
ModCmd.SetHelpFunc(thelp)
ModCmd.SetUsageFunc(tusage)

ModCmd.AddCommand(cmdmod.InfoCmd)
ModCmd.AddCommand(cmdmod.InitCmd)
ModCmd.AddCommand(cmdmod.GetCmd)
ModCmd.AddCommand(cmdmod.TidyCmd)
ModCmd.AddCommand(cmdmod.VendorCmd)

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ import (

"github.com/hofstadter-io/hof/lib/mod"

"github.com/hofstadter-io/hof/cmd/hof/flags"

"github.com/hofstadter-io/hof/cmd/hof/ga"
)

var infoLong = `print info about languages and modders known to hof mod
- no arg prints a list of known languages
- an arg prints info about the language modder configuration that would be used`
var getLong = `add a new dependency to the current module`

func InfoRun(lang string) (err error) {
func GetRun(module string) (err error) {

msg, err := mod.LangInfo(lang)
err = mod.Get(module, flags.RootPflags, flags.ModPflags)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(msg)

return err
}

var InfoCmd = &cobra.Command{
var GetCmd = &cobra.Command{

Use: "info [language]",
Use: "get <module>",

Short: "print info about languages and modders known to hof mod",
Short: "add a new dependency to the current module",

Long: infoLong,
Long: getLong,

PreRun: func(cmd *cobra.Command, args []string) {

Expand All @@ -46,15 +45,21 @@ var InfoCmd = &cobra.Command{

// Argument Parsing

var lang string
if 0 >= len(args) {
fmt.Println("missing required argument: 'module'")
cmd.Usage()
os.Exit(1)
}

var module string

if 0 < len(args) {

lang = args[0]
module = args[0]

}

err = InfoRun(lang)
err = GetRun(module)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -68,8 +73,8 @@ func init() {
return false
}

ohelp := InfoCmd.HelpFunc()
ousage := InfoCmd.UsageFunc()
ohelp := GetCmd.HelpFunc()
ousage := GetCmd.UsageFunc()
help := func(cmd *cobra.Command, args []string) {
if extra(cmd) {
return
Expand All @@ -91,7 +96,7 @@ func init() {
ga.SendCommandPath(cmd.CommandPath() + " usage")
return usage(cmd)
}
InfoCmd.SetHelpFunc(thelp)
InfoCmd.SetUsageFunc(tusage)
GetCmd.SetHelpFunc(thelp)
GetCmd.SetUsageFunc(tusage)

}
28 changes: 8 additions & 20 deletions .hof/shadow/cli/cmd/hof/cmd/mod/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (

"github.com/hofstadter-io/hof/lib/mod"

"github.com/hofstadter-io/hof/cmd/hof/flags"

"github.com/hofstadter-io/hof/cmd/hof/ga"
)

var initLong = `initialize a new module in the current directory`

func InitRun(lang string, module string) (err error) {
func InitRun(module string) (err error) {

err = mod.Init(lang, module)
err = mod.Init(module, flags.RootPflags, flags.ModPflags)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -26,7 +28,7 @@ func InitRun(lang string, module string) (err error) {

var InitCmd = &cobra.Command{

Use: "init <lang> <module>",
Use: "init <module>",

Short: "initialize a new module in the current directory",

Expand All @@ -44,34 +46,20 @@ var InitCmd = &cobra.Command{
// Argument Parsing

if 0 >= len(args) {
fmt.Println("missing required argument: 'lang'")
cmd.Usage()
os.Exit(1)
}

var lang string

if 0 < len(args) {

lang = args[0]

}

if 1 >= len(args) {
fmt.Println("missing required argument: 'module'")
cmd.Usage()
os.Exit(1)
}

var module string

if 1 < len(args) {
if 0 < len(args) {

module = args[1]
module = args[0]

}

err = InitRun(lang, module)
err = InitRun(module)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
88 changes: 88 additions & 0 deletions .hof/shadow/cli/cmd/hof/cmd/mod/tidy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package cmdmod

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/lib/mod"

"github.com/hofstadter-io/hof/cmd/hof/flags"

"github.com/hofstadter-io/hof/cmd/hof/ga"
)

var tidyLong = `recalculate dependencies and update mod files`

func TidyRun(args []string) (err error) {

err = mod.Tidy(flags.RootPflags, flags.ModPflags)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

return err
}

var TidyCmd = &cobra.Command{

Use: "tidy",

Short: "recalculate dependencies and update mod files",

Long: tidyLong,

PreRun: func(cmd *cobra.Command, args []string) {

ga.SendCommandPath(cmd.CommandPath())

},

Run: func(cmd *cobra.Command, args []string) {
var err error

// Argument Parsing

err = TidyRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

func init() {
extra := func(cmd *cobra.Command) bool {

return false
}

ohelp := TidyCmd.HelpFunc()
ousage := TidyCmd.UsageFunc()
help := func(cmd *cobra.Command, args []string) {
if extra(cmd) {
return
}
ohelp(cmd, args)
}
usage := func(cmd *cobra.Command) error {
if extra(cmd) {
return nil
}
return ousage(cmd)
}

thelp := func(cmd *cobra.Command, args []string) {
ga.SendCommandPath(cmd.CommandPath() + " help")
help(cmd, args)
}
tusage := func(cmd *cobra.Command) error {
ga.SendCommandPath(cmd.CommandPath() + " usage")
return usage(cmd)
}
TidyCmd.SetHelpFunc(thelp)
TidyCmd.SetUsageFunc(tusage)

}
10 changes: 6 additions & 4 deletions .hof/shadow/cli/cmd/hof/cmd/mod/vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (

"github.com/hofstadter-io/hof/lib/mod"

"github.com/hofstadter-io/hof/cmd/hof/flags"

"github.com/hofstadter-io/hof/cmd/hof/ga"
)

var vendorLong = `make a vendored copy of dependencies`
var vendorLong = `copy dependencies to cue.mod/pkg`

func VendorRun(args []string) (err error) {

err = mod.ProcessLangs("vendor", args)
err = mod.Vendor(flags.RootPflags, flags.ModPflags)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -26,9 +28,9 @@ func VendorRun(args []string) (err error) {

var VendorCmd = &cobra.Command{

Use: "vendor [langs...]",
Use: "vendor",

Short: "make a vendored copy of dependencies",
Short: "copy dependencies to cue.mod/pkg",

Long: vendorLong,

Expand Down
7 changes: 7 additions & 0 deletions .hof/shadow/cli/cmd/hof/flags/mod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package flags

type ModPflagpole struct {
Update bool
}

var ModPflags ModPflagpole
2 changes: 1 addition & 1 deletion ci/gha/common/vars.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Formatters: [

Versions: {
docker: "20.x" | ["20.x", "23.x"]
go: "1.20.x" | ["1.18.x", "1.19.x", "1.20.x"]
go: "1.20.x" | ["1.19.x", "1.20.x"]
os: "ubuntu-latest" | ["ubuntu-latest", "macos-latest"]
}
Loading

0 comments on commit ff02b5c

Please sign in to comment.