From 158e9d6eb8a74bc6ce3c3f2a9709de081568dc02 Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 27 Jan 2024 19:07:09 +0100 Subject: Add go project Signed-off-by: axtloss --- cmd/root.go | 22 ++++++++++++++++++++++ cmd/verify.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 cmd/root.go create mode 100644 cmd/verify.go (limited to 'cmd') diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..d212e4e --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "os" +) + +var rootCmd = &cobra.Command{ + Use: "fsverify", +} + +func init() { + rootCmd.AddCommand(NewVerifyCommand()) +} + +func Execute() { + // cobra does not exit with a non-zero return code when failing + // solution from https://github.com/spf13/cobra/issues/221 + if err := rootCmd.Execute(); err != nil { + os.Exit(1) + } +} diff --git a/cmd/verify.go b/cmd/verify.go new file mode 100644 index 0000000..3ceabbe --- /dev/null +++ b/cmd/verify.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "github.com/axtloss/fsverify/core" + "github.com/spf13/cobra" +) + +func NewVerifyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "verify", + Short: "Verify the root filesystem based on the given verification", + RunE: ValidateCommand, + SilenceUsage: true, + } + + return cmd +} + +func ValidateCommand(_ *cobra.Command, args []string) error { + node := core.Node{ + BlockStart: 0, + BlockEnd: 4 * 1000, + BlockSum: "test", + PrevNodeSum: "aaaa", + } + err := core.AddNode(node, nil) + if err != nil { + return err + } + _, err = core.ReadHeader("./test.part") + return err +} -- cgit v1.2.3