From 3c612cbfc86863adce406d105b8df4d1a2502f7c Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 3 May 2016 16:49:30 +1000
Subject: [PATCH] cmd/torrent-create: Tidy up flags and remove redundant
 function calls

Issue #80
---
 cmd/torrent-create/main.go | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/cmd/torrent-create/main.go b/cmd/torrent-create/main.go
index 9174c857..b352de9b 100644
--- a/cmd/torrent-create/main.go
+++ b/cmd/torrent-create/main.go
@@ -1,13 +1,10 @@
 package main
 
 import (
-	"io"
 	"log"
 	"os"
-	"path/filepath"
-	"strings"
 
-	"github.com/docopt/docopt-go"
+	"github.com/anacrolix/tagflag"
 
 	"github.com/anacrolix/torrent/metainfo"
 )
@@ -21,25 +18,20 @@ var (
 )
 
 func main() {
-	opts, err := docopt.Parse("Usage: torrent-create <root>", nil, true, "", true)
-	if err != nil {
-		panic(err)
+	log.SetFlags(log.Flags() | log.Lshortfile)
+	var args struct {
+		tagflag.StartPos
+		Root string
 	}
-	root := opts["<root>"].(string)
+	tagflag.Parse(&args, tagflag.Description("Creates a torrent metainfo for the file system rooted at ROOT, and outputs it to stdout."))
 	mi := metainfo.MetaInfo{
 		AnnounceList: builtinAnnounceList,
 	}
 	mi.SetDefaults()
-	err = mi.Info.BuildFromFilePath(root)
+	err := mi.Info.BuildFromFilePath(args.Root)
 	if err != nil {
 		log.Fatal(err)
 	}
-	err = mi.Info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
-		return os.Open(filepath.Join(root, strings.Join(fi.Path, string(filepath.Separator))))
-	})
-	if err != nil {
-		log.Fatalf("error generating pieces: %s", err)
-	}
 	err = mi.Write(os.Stdout)
 	if err != nil {
 		log.Fatal(err)
-- 
2.51.0