forked from xkeyideal/glide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glide.go
870 lines (798 loc) · 26.3 KB
/
glide.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
// Glide is a command line utility that manages Go project dependencies.
//
// Configuration of where to start is managed via a glide.yaml in the root of a
// project. The yaml
//
// A glide.yaml file looks like:
//
// package: github.com/Masterminds/glide
// imports:
// - package: github.com/Masterminds/cookoo
// - package: github.com/kylelemons/go-gypsy
// subpackages:
// - yaml
//
// Glide puts dependencies in a vendor directory. Go utilities require this to
// be in your GOPATH. Glide makes this easy.
//
// For more information use the `glide help` command or see https://glide.sh
package main
import (
"path/filepath"
"github.com/xkeyideal/glide/action"
"github.com/xkeyideal/glide/cache"
"github.com/xkeyideal/glide/msg"
gpath "github.com/xkeyideal/glide/path"
"github.com/xkeyideal/glide/repo"
"github.com/xkeyideal/glide/util"
"github.com/codegangsta/cli"
"fmt"
"os"
)
var version = "0.13.2-dev"
const usage = `Vendor Package Management for your Go projects.
Each project should have a 'glide.yaml' file in the project directory. Files
look something like this:
package: github.com/xkeyideal/glide
imports:
- package: github.com/xkeyideal/cookoo
version: 1.1.0
- package: github.com/kylelemons/go-gypsy
subpackages:
- yaml
For more details on the 'glide.yaml' files see the documentation at
https://glide.sh/docs/glide.yaml
`
// VendorDir default vendor directory name
var VendorDir = "vendor"
func main() {
app := cli.NewApp()
app.Name = "glide"
app.Usage = usage
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "yaml, y",
Value: "glide.yaml",
Usage: "Set a YAML configuration file.",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Quiet (no info or debug messages)",
},
cli.BoolFlag{
Name: "debug",
Usage: "Print debug verbose informational messages",
},
cli.StringFlag{
Name: "home",
Value: gpath.Home(),
Usage: "The location of Glide files",
EnvVar: "GLIDE_HOME",
},
cli.StringFlag{
Name: "tmp",
Value: "",
Usage: "The temp directory to use. Defaults to systems temp",
EnvVar: "GLIDE_TMP",
},
cli.BoolFlag{
Name: "no-color",
Usage: "Turn off colored output for log messages",
},
}
app.CommandNotFound = func(c *cli.Context, command string) {
// TODO: Set some useful env vars.
action.Plugin(command, os.Args)
}
app.Before = startup
app.After = shutdown
app.Commands = commands()
// Detect errors from the Before and After calls and exit on them.
if err := app.Run(os.Args); err != nil {
msg.Err(err.Error())
os.Exit(1)
}
// If there was an Error message exit non-zero.
if msg.HasErrored() {
m := msg.Color(msg.Red, "An Error has occurred")
msg.Msg(m)
os.Exit(2)
}
}
func commands() []cli.Command {
return []cli.Command{
{
Name: "create",
ShortName: "init",
Usage: "Initialize a new project, creating a glide.yaml file",
Description: `This command starts from a project without Glide and
sets it up. It generates a glide.yaml file, parsing your codebase to guess
the dependencies to include. Once this step is done you may edit the
glide.yaml file to update imported dependency properties such as the version
or version range to include.
To fetch the dependencies you may run 'glide install'.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "skip-import",
Usage: "When initializing skip importing from other package managers.",
},
cli.BoolFlag{
Name: "non-interactive",
Usage: "Disable interactive prompts.",
},
},
Action: func(c *cli.Context) error {
action.Create(".", c.Bool("skip-import"), c.Bool("non-interactive"))
return nil
},
},
{
Name: "config-wizard",
ShortName: "cw",
Usage: "Wizard that makes optional suggestions to improve config in a glide.yaml file.",
Description: `Glide will analyze a projects glide.yaml file and the imported
projects to find ways the glide.yaml file can potentially be improved. It
will then interactively make suggestions that you can skip or accept.`,
Action: func(c *cli.Context) error {
action.ConfigWizard(".")
return nil
},
},
{
Name: "get",
Usage: "Install one or more packages into `vendor/` and add dependency to glide.yaml.",
Description: `Gets one or more package (like 'go get') and then adds that file
to the glide.yaml file. Multiple package names can be specified on one line.
$ glide get github.com/Masterminds/cookoo/web
The above will install the project github.com/Masterminds/cookoo and add
the subpackage 'web'.
If a fetched dependency has a glide.yaml file, configuration from Godep,
GPM, GOM, or GB Glide that configuration will be used to find the dependencies
and versions to fetch. If those are not available the dependent packages will
be fetched as either a version specified elsewhere or the latest version.
When adding a new dependency Glide will perform an update to work out
the versions for the dependencies of this dependency (transitive ones). This
will generate an updated glide.lock file with specific locked versions to use.
The '--strip-vendor' flag will remove any nested 'vendor' folders and
'Godeps/_workspace' folders after an update (along with undoing any Godep
import rewriting). Note, The Godeps specific functionality is deprecated and
will be removed when most Godeps users have migrated to using the vendor
folder.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "test",
Usage: "Add test dependencies.",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Use http:// rather than https:// to retrieve packages.",
},
cli.BoolFlag{
Name: "no-recursive, quick",
Usage: "Disable updating dependencies' dependencies.",
},
cli.BoolFlag{
Name: "force",
Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.",
},
cli.BoolFlag{
Name: "all-dependencies",
Usage: "This will resolve all dependencies for all packages, not just those directly used.",
},
cli.BoolFlag{
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache",
Usage: "When downloading dependencies attempt to cache them.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache-gopath",
Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
Hidden: true,
},
cli.BoolFlag{
Name: "use-gopath",
Usage: "Copy dependencies from the GOPATH if they exist there.",
Hidden: true,
},
cli.BoolFlag{
Name: "resolve-current",
Usage: "Resolve dependencies for only the current system rather than all build modes.",
},
cli.BoolFlag{
Name: "strip-vcs, s",
Usage: "Removes version control metadata (e.g, .git directory) from the vendor folder.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories.",
},
cli.BoolFlag{
Name: "non-interactive",
Usage: "Disable interactive prompts.",
},
cli.BoolFlag{
Name: "skip-test",
Usage: "Resolve dependencies in test files.",
},
},
Action: func(c *cli.Context) error {
if c.Bool("delete") {
msg.Warn("The --delete flag is deprecated. This now works by default.")
}
if c.Bool("update-vendored") {
msg.Warn("The --update-vendored flag is deprecated. This now works by default.")
}
if c.String("file") != "" {
msg.Warn("The --file flag is deprecated.")
}
if c.Bool("cache") {
msg.Warn("The --cache flag is deprecated. This now works by default.")
}
if c.Bool("cache-gopath") {
msg.Warn("The --cache-gopath flag is deprecated.")
}
if c.Bool("use-gopath") {
msg.Warn("The --use-gopath flag is deprecated. Please see overrides.")
}
if c.Bool("strip-vcs") {
msg.Warn("The --strip-vcs flag is deprecated. This now works by default.")
}
if len(c.Args()) < 1 {
fmt.Println("Oops! Package name is required.")
os.Exit(1)
}
if c.Bool("resolve-current") {
util.ResolveCurrent = true
msg.Warn("Only resolving dependencies for the current OS/Arch.")
}
inst := repo.NewInstaller()
inst.Force = c.Bool("force")
inst.ResolveAllFiles = c.Bool("all-dependencies")
inst.ResolveTest = !c.Bool("skip-test")
packages := []string(c.Args())
insecure := c.Bool("insecure")
action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vendor"), c.Bool("non-interactive"), c.Bool("test"))
return nil
},
},
{
Name: "remove",
ShortName: "rm",
Usage: "Remove a package from the glide.yaml file, and regenerate the lock file.",
Description: `This takes one or more package names, and removes references from the glide.yaml file.
This will rebuild the glide lock file re-resolving the depencies.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "delete,d",
Usage: "Also delete from vendor/ any packages that are no longer used.",
},
},
Action: func(c *cli.Context) error {
if len(c.Args()) < 1 {
fmt.Println("Oops! At least one package name is required.")
os.Exit(1)
}
if c.Bool("delete") {
// FIXME: Implement this in the installer.
fmt.Println("Delete is not currently implemented.")
}
inst := repo.NewInstaller()
inst.Force = c.Bool("force")
packages := []string(c.Args())
action.Remove(packages, inst)
return nil
},
},
{
Name: "import",
Usage: "Import files from other dependency management systems.",
Subcommands: []cli.Command{
{
Name: "godep",
Usage: "Import Godep's Godeps.json files and display the would-be yaml file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file.",
},
},
Action: func(c *cli.Context) error {
action.ImportGodep(c.String("file"))
return nil
},
},
{
Name: "gpm",
Usage: "Import GPM's Godeps and Godeps-Git files and display the would-be yaml file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file.",
},
},
Action: func(c *cli.Context) error {
action.ImportGPM(c.String("file"))
return nil
},
},
{
Name: "gb",
Usage: "Import gb's manifest file and display the would-be yaml file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file.",
},
},
Action: func(c *cli.Context) error {
action.ImportGB(c.String("file"))
return nil
},
},
{
Name: "gom",
Usage: "Import Gomfile and display the would-be yaml file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file.",
},
},
Action: func(c *cli.Context) error {
action.ImportGom(c.String("file"))
return nil
},
},
},
},
{
Name: "name",
Usage: "Print the name of this project.",
Description: `Read the glide.yaml file and print the name given on the 'package' line.`,
Action: func(c *cli.Context) error {
action.Name()
return nil
},
},
{
Name: "novendor",
ShortName: "nv",
Usage: "List all non-vendor paths in a directory.",
Description: `Given a directory, list all the relevant Go paths that are not vendored.
Example:
$ go test $(glide novendor)`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "dir,d",
Usage: "Specify a directory to run novendor against.",
Value: ".",
},
cli.BoolFlag{
Name: "no-subdir,x",
Usage: "Specify this to prevent nv from append '/...' to all directories.",
},
},
Action: func(c *cli.Context) error {
action.NoVendor(c.String("dir"), true, !c.Bool("no-subdir"))
return nil
},
},
{
Name: "rebuild",
Usage: "Rebuild ('go build') the dependencies",
Description: `(Deprecated) This rebuilds the packages' '.a' files. On some systems
this can improve performance on subsequent 'go run' and 'go build' calls.`,
Action: func(c *cli.Context) error {
action.Rebuild()
return nil
},
},
{
Name: "install",
ShortName: "i",
Usage: "Install a project's dependencies",
Description: `This uses the native VCS of each package to install
the appropriate version. There are two ways a project's dependencies can
be installed. When there is a glide.yaml file defining the dependencies but
no lock file (glide.lock) the dependencies are installed using the "update"
command and a glide.lock file is generated pinning all dependencies. If a
glide.lock file is already present the dependencies are installed or updated
from the lock file.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "delete",
Usage: "Delete vendor packages not specified in config.",
Hidden: true,
},
cli.BoolFlag{
Name: "force",
Usage: "If there was a change in the repo or VCS switch to new one. Warning: changes will be lost.",
},
cli.BoolFlag{
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning: this may destroy local modifications to vendor/.",
Hidden: true,
},
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file. (DEPRECATED: This has no impact.)",
Hidden: true,
},
cli.BoolFlag{
Name: "cache",
Usage: "When downloading dependencies attempt to cache them.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache-gopath",
Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
Hidden: true,
},
cli.BoolFlag{
Name: "use-gopath",
Usage: "Copy dependencies from the GOPATH if they exist there.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vcs, s",
Usage: "Removes version control metadata (e.g, .git directory) from the vendor folder.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories.",
},
cli.BoolFlag{
Name: "skip-test",
Usage: "Resolve dependencies in test files.",
},
},
Action: func(c *cli.Context) error {
if c.Bool("delete") {
msg.Warn("The --delete flag is deprecated. This now works by default.")
}
if c.Bool("update-vendored") {
msg.Warn("The --update-vendored flag is deprecated. This now works by default.")
}
if c.String("file") != "" {
msg.Warn("The --flag flag is deprecated.")
}
if c.Bool("cache") {
msg.Warn("The --cache flag is deprecated. This now works by default.")
}
if c.Bool("cache-gopath") {
msg.Warn("The --cache-gopath flag is deprecated.")
}
if c.Bool("use-gopath") {
msg.Warn("The --use-gopath flag is deprecated. Please see overrides.")
}
if c.Bool("strip-vcs") {
msg.Warn("The --strip-vcs flag is deprecated. This now works by default.")
}
installer := repo.NewInstaller()
installer.Force = c.Bool("force")
installer.Home = c.GlobalString("home")
installer.ResolveTest = !c.Bool("skip-test")
action.Install(installer, c.Bool("strip-vendor"))
return nil
},
},
{
Name: "update",
ShortName: "up",
Usage: "Update a project's dependencies",
Description: `This updates the dependencies by scanning the codebase
to determine the needed dependencies and fetching them following the rules
in the glide.yaml file. When no rules exist the tip of the default branch
is used. For more details see https://glide.sh/docs/glide.yaml
If a dependency has a glide.yaml file, update will read that file and
use the information contained there. Those dependencies are maintained in
the top level 'vendor/' directory. 'vendor/foo/bar' will have its
dependencies stored in 'vendor/'. This behavior can be disabled with
'--no-recursive'. When this behavior is skipped a glide.lock file is not
generated because the full dependency tree cannot be known.
Glide will also import Godep, GB, GOM, and GPM files as it finds them in dependencies.
It will create a glide.yaml file from the Godeps data, and then update. This
has no effect if '--no-recursive' is set.
The '--strip-vendor' flag will remove any nested 'vendor' folders and
'Godeps/_workspace' folders after an update (along with undoing any Godep
import rewriting). Note, the Godeps specific functionality is deprecated and
will be removed when most Godeps users have migrated to using the vendor
folder.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "delete",
Usage: "Delete vendor packages not specified in config.",
Hidden: true,
},
cli.BoolFlag{
Name: "no-recursive, quick",
Usage: "Disable updating dependencies' dependencies. Only update things in glide.yaml.",
},
cli.BoolFlag{
Name: "force",
Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.",
},
cli.BoolFlag{
Name: "all-dependencies",
Usage: "This will resolve all dependencies for all packages, not just those directly used.",
},
cli.BoolFlag{
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.",
Hidden: true,
},
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache",
Usage: "When downloading dependencies attempt to cache them.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache-gopath",
Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
Hidden: true,
},
cli.BoolFlag{
Name: "use-gopath",
Usage: "Copy dependencies from the GOPATH if they exist there.",
Hidden: true,
},
cli.BoolFlag{
Name: "resolve-current",
Usage: "Resolve dependencies for only the current system rather than all build modes.",
},
cli.BoolFlag{
Name: "strip-vcs, s",
Usage: "Removes version control metadata (e.g, .git directory) from the vendor folder.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories.",
},
cli.BoolFlag{
Name: "skip-test",
Usage: "Resolve dependencies in test files.",
},
},
Action: func(c *cli.Context) error {
if c.Bool("delete") {
msg.Warn("The --delete flag is deprecated. This now works by default.")
}
if c.Bool("update-vendored") {
msg.Warn("The --update-vendored flag is deprecated. This now works by default.")
}
if c.String("file") != "" {
msg.Warn("The --flag flag is deprecated.")
}
if c.Bool("cache") {
msg.Warn("The --cache flag is deprecated. This now works by default.")
}
if c.Bool("cache-gopath") {
msg.Warn("The --cache-gopath flag is deprecated.")
}
if c.Bool("use-gopath") {
msg.Warn("The --use-gopath flag is deprecated. Please see overrides.")
}
if c.Bool("strip-vcs") {
msg.Warn("The --strip-vcs flag is deprecated. This now works by default.")
}
if c.Bool("resolve-current") {
util.ResolveCurrent = true
msg.Warn("Only resolving dependencies for the current OS/Arch")
}
installer := repo.NewInstaller()
installer.Force = c.Bool("force")
installer.ResolveAllFiles = c.Bool("all-dependencies")
installer.Home = c.GlobalString("home")
installer.ResolveTest = !c.Bool("skip-test")
action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vendor"))
return nil
},
},
{
Name: "tree",
Usage: "(Deprecated) Tree prints the dependencies of this project as a tree.",
Description: `This scans a project's source files and builds a tree
representation of the import graph.
It ignores testdata/ and directories that begin with . or _. Packages in
vendor/ are only included if they are referenced by the main project or
one of its dependencies.
Note, for large projects this can display a large list tens of thousands of
lines long.`,
Action: func(c *cli.Context) error {
action.Tree(".", false)
return nil
},
},
{
Name: "list",
Usage: "List prints all dependencies that the present code references.",
Description: `List scans your code and lists all of the packages that are used.
It does not use the glide.yaml. Instead, it inspects the code to determine what packages are
imported.
Directories that begin with . or _ are ignored, as are testdata directories. Packages in
vendor are only included if they are used by the project.`,
Action: func(c *cli.Context) error {
action.List(".", true, c.String("output"))
return nil
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Usage: "Output format. One of: json|json-pretty|text",
Value: "text",
},
},
},
{
Name: "info",
Usage: "Info prints information about this project",
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Usage: `Format of the information wanted (required).`,
},
},
Description: `A format containing the text with replacement variables
has to be passed in. Those variables are:
%n - name
%d - description
%h - homepage
%l - license
For example, given a project with the following glide.yaml:
package: foo
homepage: https://example.com
license: MIT
description: Some example description
Then running the following commands:
glide info -f %n
prints 'foo'
glide info -f "License: %l"
prints 'License: MIT'
glide info -f "%n - %d - %h - %l"
prints 'foo - Some example description - https://example.com - MIT'`,
Action: func(c *cli.Context) error {
if c.IsSet("format") {
action.Info(c.String("format"))
} else {
cli.ShowCommandHelp(c, c.Command.Name)
}
return nil
},
},
{
Name: "cache-clear",
ShortName: "cc",
Usage: "Clears the Glide cache.",
Action: func(c *cli.Context) error {
action.CacheClear()
return nil
},
},
{
Name: "about",
Usage: "Learn about Glide",
Action: func(c *cli.Context) error {
action.About()
return nil
},
},
{
Name: "mirror",
Usage: "Manage mirrors",
Description: `Mirrors provide the ability to replace a repo location with
another location that's a mirror of the original. This is useful when you want
to have a cache for your continuous integration (CI) system or if you want to
work on a dependency in a local location.
The mirrors are stored in a mirrors.yaml file in your GLIDE_HOME.
The three commands to manage mirrors are 'list', 'set', and 'remove'.
Use 'set' in the form:
glide mirror set [original] [replacement]
or
glide mirror set [original] [replacement] --vcs [type] --base [directory]
for example,
glide mirror set https://github.com/example/foo https://git.example.com/example/foo.git
glide mirror set https://github.com/example/foo file:///path/to/local/repo --vcs git
glide mirror set https://golang.org/x/sys/unix https://github.com/golang/sys --base golang.org/x/sys
Use 'remove' in the form:
glide mirror remove [original]
for example,
glide mirror remove https://github.com/example/foo`,
Subcommands: []cli.Command{
{
Name: "list",
Usage: "List the current mirrors",
Action: func(c *cli.Context) error {
return action.MirrorsList()
},
},
{
Name: "set",
Usage: "Set a mirror. This overwrites an existing entry if one exists",
Description: `Use 'set' in the form:
glide mirror set [original] [replacement]
or
glide mirror set [original] [replacement] --vcs [type] -- base [directory]
for example,
glide mirror set https://github.com/example/foo https://git.example.com/example/foo.git
glide mirror set https://github.com/example/foo file:///path/to/local/repo --vcs git
glide mirror set https://golang.org/x/sys/unix https://github.com/golang/sys --base golang.org/x/sys
`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "vcs",
Usage: "The VCS type to use. Autodiscovery is attempted when not supplied. Can be one of git, svn, bzr, or hg",
},
cli.StringFlag{
Name: "base",
Usage: "The mirror repo files copy to directory",
},
},
Action: func(c *cli.Context) error {
return action.MirrorsSet(c.Args().Get(0), c.Args().Get(1), c.String("vcs"), c.String("base"))
},
},
{
Name: "remove",
ShortName: "rm",
Usage: "Remove a mirror",
Description: `Use 'remove' in the form:
glide mirror remove [original]
for example,
glide mirror remove https://github.com/example/foo`,
Action: func(c *cli.Context) error {
return action.MirrorsRemove(c.Args().Get(0))
},
},
},
},
}
}
// startup sets up the base environment.
//
// It does not assume the presence of a Glide.yaml file or vendor/ directory,
// so it can be used by any Glide command.
func startup(c *cli.Context) error {
action.Debug(c.Bool("debug"))
action.NoColor(c.Bool("no-color"))
action.Quiet(c.Bool("quiet"))
action.Init(c.String("yaml"), c.String("home"))
action.EnsureGoVendor()
gpath.Tmp = c.String("tmp")
return nil
}
func shutdown(c *cli.Context) error {
cache.SystemUnlock()
return nil
}
// Get the path to the glide.yaml file.
//
// This returns the name of the path, even if the file does not exist. The value
// may be set by the user, or it may be the default.
func glidefile(c *cli.Context) string {
path := c.String("file")
if path == "" {
// For now, we construct a basic assumption. In the future, we could
// traverse backward to see if a glide.yaml exists in a parent.
path = "./glide.yaml"
}
a, err := filepath.Abs(path)
if err != nil {
// Underlying fs didn't provide working dir.
return path
}
return a
}