Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: client/cmd/cipd/friendly.go

Issue 1862303004: cipd: shared tag cache (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Remove caveat, inline help Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/cipd/client.go ('k') | client/cmd/cipd/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "errors" 9 "errors"
10 "flag" 10 "flag"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Config file parsing. 82 // Config file parsing.
83 83
84 // installationSiteConfig is stored in .cipd/config.json. 84 // installationSiteConfig is stored in .cipd/config.json.
85 type installationSiteConfig struct { 85 type installationSiteConfig struct {
86 // ServiceURL is https://<hostname> of a backend to use by default. 86 // ServiceURL is https://<hostname> of a backend to use by default.
87 ServiceURL string 87 ServiceURL string
88 // DefaultVersion is what version to install if not specified. 88 // DefaultVersion is what version to install if not specified.
89 DefaultVersion string 89 DefaultVersion string
90 // TrackedVersions is mapping package name -> version to use in 'update' . 90 // TrackedVersions is mapping package name -> version to use in 'update' .
91 TrackedVersions map[string]string 91 TrackedVersions map[string]string
92 // CacheDir contains shared cache.
93 CacheDir string
92 } 94 }
93 95
94 // read loads JSON from given path. 96 // read loads JSON from given path.
95 func (c *installationSiteConfig) read(path string) error { 97 func (c *installationSiteConfig) read(path string) error {
96 *c = installationSiteConfig{} 98 *c = installationSiteConfig{}
97 r, err := os.Open(path) 99 r, err := os.Open(path)
98 if err != nil { 100 if err != nil {
99 return err 101 return err
100 } 102 }
101 defer r.Close() 103 defer r.Close()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 fmt.Printf("Site root initialized at %s.\n", rootDir) 194 fmt.Printf("Site root initialized at %s.\n", rootDir)
193 return site, nil 195 return site, nil
194 } 196 }
195 197
196 // initClient initializes cipd.Client to use to talk to backend. Can be called 198 // initClient initializes cipd.Client to use to talk to backend. Can be called
197 // only once. Use it directly via site.client. 199 // only once. Use it directly via site.client.
198 func (site *installationSite) initClient(authFlags authcli.Flags) (err error) { 200 func (site *installationSite) initClient(authFlags authcli.Flags) (err error) {
199 if site.client != nil { 201 if site.client != nil {
200 return errors.New("client is already initialized") 202 return errors.New("client is already initialized")
201 } 203 }
202 » serviceOpts := ServiceOptions{ 204 » clientOpts := ClientOptions{
203 authFlags: authFlags, 205 authFlags: authFlags,
204 serviceURL: site.cfg.ServiceURL, 206 serviceURL: site.cfg.ServiceURL,
207 cacheDir: site.cfg.CacheDir,
205 } 208 }
206 » site.client, err = serviceOpts.makeCipdClient(site.siteRoot) 209 » site.client, err = clientOpts.makeCipdClient(site.siteRoot)
207 return 210 return
208 } 211 }
209 212
210 // closeClient closes the underlying cipd.Client if necessary. 213 // closeClient closes the underlying cipd.Client if necessary.
211 func (site *installationSite) closeClient() { 214 func (site *installationSite) closeClient() {
212 if site.client != nil { 215 if site.client != nil {
213 site.client.Close() 216 site.client.Close()
214 site.client = nil 217 site.client = nil
215 } 218 }
216 } 219 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 "Unless -force is given, the new site root directory should be e mpty (or " + 378 "Unless -force is given, the new site root directory should be e mpty (or " +
376 "do not exist at all) and not be under some other existing site root. " + 379 "do not exist at all) and not be under some other existing site root. " +
377 "The command will create <root>/.cipd subdirectory with some " + 380 "The command will create <root>/.cipd subdirectory with some " +
378 "configuration files. This directory is used by CIPD client to k eep " + 381 "configuration files. This directory is used by CIPD client to k eep " +
379 "track of what is installed in the site root.", 382 "track of what is installed in the site root.",
380 CommandRun: func() subcommands.CommandRun { 383 CommandRun: func() subcommands.CommandRun {
381 c := &initRun{} 384 c := &initRun{}
382 c.registerBaseFlags() 385 c.registerBaseFlags()
383 c.Flags.BoolVar(&c.force, "force", false, "Create the site root even if the directory is not empty or already under another site root directory. ") 386 c.Flags.BoolVar(&c.force, "force", false, "Create the site root even if the directory is not empty or already under another site root directory. ")
384 c.Flags.StringVar(&c.serviceURL, "service-url", "", "URL of a ba ckend to use instead of the default one.") 387 c.Flags.StringVar(&c.serviceURL, "service-url", "", "URL of a ba ckend to use instead of the default one.")
388 c.Flags.StringVar(&c.cacheDir, "cache-dir", "", "Directory for s hared cache")
385 return c 389 return c
386 }, 390 },
387 } 391 }
388 392
389 type initRun struct { 393 type initRun struct {
390 Subcommand 394 Subcommand
391 395
392 force bool 396 force bool
393 serviceURL string 397 serviceURL string
398 cacheDir string
394 } 399 }
395 400
396 func (c *initRun) Run(a subcommands.Application, args []string) int { 401 func (c *initRun) Run(a subcommands.Application, args []string) int {
397 if !c.init(args, 0, 1) { 402 if !c.init(args, 0, 1) {
398 return 1 403 return 1
399 } 404 }
400 rootDir := "." 405 rootDir := "."
401 if len(args) == 1 { 406 if len(args) == 1 {
402 rootDir = args[0] 407 rootDir = args[0]
403 } 408 }
404 site, err := initInstallationSite(rootDir, c.force) 409 site, err := initInstallationSite(rootDir, c.force)
405 if err != nil { 410 if err != nil {
406 return c.done(nil, err) 411 return c.done(nil, err)
407 } 412 }
408 err = site.modifyConfig(func(cfg *installationSiteConfig) error { 413 err = site.modifyConfig(func(cfg *installationSiteConfig) error {
409 cfg.ServiceURL = c.serviceURL 414 cfg.ServiceURL = c.serviceURL
415 cfg.CacheDir = c.cacheDir
410 return nil 416 return nil
411 }) 417 })
412 return c.done(site.siteRoot, err) 418 return c.done(site.siteRoot, err)
413 } 419 }
414 420
415 //////////////////////////////////////////////////////////////////////////////// 421 ////////////////////////////////////////////////////////////////////////////////
416 // 'install' subcommand. 422 // 'install' subcommand.
417 423
418 var cmdInstall = &subcommands.Command{ 424 var cmdInstall = &subcommands.Command{
419 UsageLine: "install <package> [<version>] [options]", 425 UsageLine: "install <package> [<version>] [options]",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 func (c *installedRun) Run(a subcommands.Application, args []string) int { 502 func (c *installedRun) Run(a subcommands.Application, args []string) int {
497 if !c.init(args, 0, -1) { 503 if !c.init(args, 0, -1) {
498 return 1 504 return 1
499 } 505 }
500 site, err := getInstallationSite(c.rootDir) 506 site, err := getInstallationSite(c.rootDir)
501 if err != nil { 507 if err != nil {
502 return c.done(nil, err) 508 return c.done(nil, err)
503 } 509 }
504 return c.doneWithPins(site.installedPackages(args)) 510 return c.doneWithPins(site.installedPackages(args))
505 } 511 }
OLDNEW
« no previous file with comments | « client/cipd/client.go ('k') | client/cmd/cipd/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698