-
Notifications
You must be signed in to change notification settings - Fork 2
/
lsFiles.go
42 lines (36 loc) · 823 Bytes
/
lsFiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var (
isShowStaged bool
)
// lsFilesCmd represents the lsFiles command
var lsFilesCmd = &cobra.Command{
Use: "ls-files",
Short: "print out index",
Long: "this is a command to print out index",
PreRunE: func(cmd *cobra.Command, args []string) error {
if client.RootGoitPath == "" {
return ErrGoitNotInitialized
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
for _, entry := range client.Idx.Entries {
if isShowStaged {
fmt.Printf("%s %s\n", entry.Hash, entry.Path)
} else {
fmt.Printf("%s\n", entry.Path)
}
}
},
}
func init() {
rootCmd.AddCommand(lsFilesCmd)
lsFilesCmd.Flags().BoolVarP(&isShowStaged, "staged", "s", false, "show staged contents")
}