A read-only clone of the dehub project, for until dehub.dev can be brought back online.
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.
 
 
dehub/cmd/dehub/main.go

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
})
}