diff --git a/cmd/spawn/main.go b/cmd/spawn/main.go index 02e1ff8..4cbe741 100644 --- a/cmd/spawn/main.go +++ b/cmd/spawn/main.go @@ -5,6 +5,7 @@ import ( "os" "github.com/prajeenrg/spawn/pkg/image" + "github.com/prajeenrg/spawn/pkg/text" "github.com/urfave/cli/v2" ) @@ -50,5 +51,19 @@ func main() { return nil }, }, + { + Name: "text", + Usage: "generate dummy text files", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "file", Aliases: []string{"f"}, Required: true}, + &cli.UintFlag{Name: "size", Aliases: []string{"s"}, Value: 100}, + }, + Action: func(ctx *cli.Context) error { + name := ctx.String("file") + size := ctx.Uint("size") + text.MakeDummyFile(name, size) + return nil + }, + }, } } diff --git a/pkg/text/text.go b/pkg/text/text.go new file mode 100644 index 0000000..70330ae --- /dev/null +++ b/pkg/text/text.go @@ -0,0 +1,19 @@ +package text + +import ( + "log" + + "github.com/prajeenrg/spawn/pkg/util" +) + +func MakeDummyFile(name string, size uint) { + file := util.CreateFile(name) + defer file.Close() + + _, b := util.GetRandomBytes(size) + _, err := file.Write(b) + + if err != nil { + log.Fatalf("Writing to %s failed", name) + } +}