arche / internal/cli/root.go

commit 154431fd
 1package cli
 2
 3import (
 4	"fmt"
 5	"os"
 6
 7	"arche/internal/repo"
 8
 9	"github.com/spf13/cobra"
10)
11
12var version = "0.1.0"
13
14func isTerminal(f *os.File) bool {
15	fi, err := f.Stat()
16	if err != nil {
17		return false
18	}
19	return (fi.Mode() & os.ModeCharDevice) != 0
20}
21
22var Root = &cobra.Command{
23	Use:           "arche",
24	Short:         "Arche - a modern distributed version control system",
25	SilenceUsage:  true,
26	SilenceErrors: true,
27	Version:       version,
28}
29
30func init() {
31	Root.AddCommand(
32		initCmd,
33		snapCmd,
34		statusCmd,
35		diffCmd,
36		logCmd,
37		coCmd,
38		undoCmd,
39		opLogCmd,
40		bookmarkCmd,
41		mergeCmd,
42		rebaseCmd,
43		resolveCmd,
44		splitCmd,
45		foldCmd,
46		phaseCmd,
47		syncCmd,
48		uiCmd,
49		serveCmd,
50		hooksCmd,
51		cloneCmd,
52		gitImportCmd,
53		bundleCmd,
54		squashCmd,
55		gcCmd,
56		worktreeCmd,
57		watchCmd,
58		wikiCmd,
59		lockCmd,
60		bisectCmd,
61		explainCmd,
62		stackCmd,
63		grepCmd,
64	)
65}
66
67func openRepo() *repo.Repo {
68	wd, err := os.Getwd()
69	if err != nil {
70		fmt.Fprintf(os.Stderr, "arche: %v\n", err)
71		os.Exit(1)
72	}
73	r, err := repo.Open(wd)
74	if err != nil {
75		fmt.Fprintf(os.Stderr, "arche: %v\n", err)
76		os.Exit(1)
77	}
78	return r
79}