You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"dehub.dev/src/dehub.git"
|
|
"dehub.dev/src/dehub.git/cmd/dehub/dcmd"
|
|
)
|
|
|
|
type cmdCtxKey int
|
|
|
|
const (
|
|
cmdCtxKeyRepo cmdCtxKey = iota
|
|
)
|
|
|
|
func ctxRepo(ctx context.Context) *dehub.Repo {
|
|
repo, ok := ctx.Value(cmdCtxKeyRepo).(*dehub.Repo)
|
|
if !ok {
|
|
panic("repo not initialized on the command context")
|
|
}
|
|
return repo
|
|
}
|
|
|
|
func main() {
|
|
cmd := dcmd.New()
|
|
flag := cmd.FlagSet()
|
|
bare := flag.Bool("bare", false, "If set then dehub will expect to be working with a bare repo")
|
|
|
|
cmd.SubCmd("commit", "commits staged changes to the head of the current branch", cmdCommit)
|
|
cmd.SubCmd("verify", "verifies one or more commits as having the proper credentials", cmdVerify)
|
|
cmd.SubCmd("hook", "use dehub as a git hook", cmdHook)
|
|
cmd.SubCmd("combine", "Combine multiple change and credential commits into a single commit", cmdCombine)
|
|
|
|
cmd.Run(func() (context.Context, error) {
|
|
repo, err := dehub.OpenRepo(".", dehub.OpenBare(*bare))
|
|
if err != nil {
|
|
wd, _ := os.Getwd()
|
|
return nil, fmt.Errorf("failed to OpenRepo at %q: %w", wd, err)
|
|
}
|
|
|
|
return context.WithValue(context.Background(), cmdCtxKeyRepo, repo), nil
|
|
})
|
|
}
|
|
|