@@ -58,42 +58,43 @@ func main() {
5858 outDir := flag .String ("out" , "obj/api" , "Output directory (default obj/api)" )
5959 projectID := flag .String ("project" , "" , "Project ID to use. Required when using -new-modules." )
6060 newMods := flag .Bool ("new-modules" , false , "Process all new modules with the given prefix. Uses timestamp in Datastore. Stores results in $out/$mod." )
61+ // TODO: flag to set output URL path
6162
6263 log .SetPrefix ("[godocfx] " )
6364
6465 flag .Parse ()
65- if flag .NArg () != 1 {
66+ if flag .NArg () == 0 {
6667 log .Fatalf ("%s missing required argument: module path/prefix" , os .Args [0 ])
6768 }
6869
69- mod := flag .Arg ( 0 )
70+ modNames := flag .Args ( )
7071 var mods []indexEntry
7172 if * newMods {
7273 if * projectID == "" {
7374 log .Fatal ("Must set -project when using -new-modules" )
7475 }
7576 var err error
76- mods , err = newModules (context .Background (), indexClient {}, & dsTimeSaver {projectID : * projectID }, mod )
77+ mods , err = newModules (context .Background (), indexClient {}, & dsTimeSaver {projectID : * projectID }, modNames )
7778 if err != nil {
7879 log .Fatal (err )
7980 }
8081 } else {
81- modPath := mod
82- version := "latest"
83- if strings .Contains (mod , "@" ) {
84- parts := strings .Split (mod , "@" )
85- if len (parts ) != 2 {
86- log .Fatal ("module arg expected only one '@'" )
82+ for _ , mod := range modNames {
83+ modPath := mod
84+ version := "latest"
85+ if strings .Contains (mod , "@" ) {
86+ parts := strings .Split (mod , "@" )
87+ if len (parts ) != 2 {
88+ log .Fatal ("module arg expected only one '@'" )
89+ }
90+ modPath = parts [0 ]
91+ version = parts [1 ]
8792 }
88- modPath = parts [0 ]
89- version = parts [1 ]
90- }
91- modPath = strings .TrimSuffix (modPath , "/..." ) // No /... needed.
92- mods = []indexEntry {
93- {
93+ modPath = strings .TrimSuffix (modPath , "/..." ) // No /... needed.
94+ mods = append (mods , indexEntry {
9495 Path : modPath ,
9596 Version : version ,
96- },
97+ })
9798 }
9899 }
99100
@@ -105,21 +106,19 @@ func main() {
105106 return
106107 }
107108 // Create a temp module so we can get the exact version asked for.
108- tempDir , err := ioutil .TempDir ("" , "godocfx-*" )
109+ workingDir , err := ioutil .TempDir ("" , "godocfx-*" )
109110 if err != nil {
110111 log .Fatalf ("ioutil.TempDir: %v" , err )
111112 }
112- runCmd (tempDir , "go" , "mod" , "init" , "cloud.google.com/go/lets-build-some-docs" )
113+ // Use a fake module that doesn't start with cloud.google.com/go.
114+ runCmd (workingDir , "go" , "mod" , "init" , "cloud.google.com/lets-build-some-docs" )
113115 for _ , m := range mods {
114116 log .Printf ("Processing %s@%s" , m .Path , m .Version )
115117
116- path := * outDir
117- // If we have more than one module, we need a more specific out path.
118- if len (mods ) > 1 {
119- path = filepath .Join (path , fmt .Sprintf ("%s@%s" , m .Path , m .Version ))
120- }
121- if err := process (m , tempDir , path , * print ); err != nil {
122- log .Printf ("Failed to process %v" , m )
118+ // Always output to specific directory.
119+ path := filepath .Join (* outDir , fmt .Sprintf ("%s@%s" , m .Path , m .Version ))
120+ if err := process (m , workingDir , path , * print ); err != nil {
121+ log .Printf ("Failed to process %v: %v" , m , err )
123122 }
124123 log .Printf ("Done with %s@%s" , m .Path , m .Version )
125124 }
@@ -138,22 +137,23 @@ func runCmd(dir, name string, args ...string) error {
138137 return nil
139138}
140139
141- func process (mod indexEntry , tempDir , outDir string , print bool ) error {
140+ func process (mod indexEntry , workingDir , outDir string , print bool ) error {
142141 // Be sure to get the module and run the module loader in the tempDir.
143- if err := runCmd (tempDir , "go" , "mod" , "tidy" ); err != nil {
144- return err
142+ if err := runCmd (workingDir , "go" , "mod" , "tidy" ); err != nil {
143+ return fmt . Errorf ( "go mod tidy error: %v" , err )
145144 }
146- if err := runCmd (tempDir , "go" , "get" , mod .Path + "@" + mod .Version ); err != nil {
147- return err
145+ if err := runCmd (workingDir , "go" , "get" , "-d" , "-t" , mod .Path + "/... @" + mod .Version ); err != nil {
146+ return fmt . Errorf ( "go get %s@%s: %v" , mod . Path , mod . Version , err )
148147 }
149148
149+ log .Println ("Starting to parse" )
150150 optionalExtraFiles := []string {}
151151 filter := []string {
152152 "cloud.google.com/go/analytics" ,
153153 "cloud.google.com/go/area120" ,
154154 "cloud.google.com/go/gsuiteaddons" ,
155155 }
156- r , err := parse (mod .Path + "/..." , tempDir , optionalExtraFiles , filter )
156+ r , err := parse (mod .Path + "/..." , workingDir , optionalExtraFiles , filter )
157157 if err != nil {
158158 return fmt .Errorf ("parse: %v" , err )
159159 }
0 commit comments