| OLD | NEW |
| 1 // Copyright 2014 The LUCI Authors. All rights reserved. | 1 // Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package cli | 5 package cli |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/sha1" | 8 "crypto/sha1" |
| 9 "encoding/hex" | 9 "encoding/hex" |
| 10 "encoding/json" | 10 "encoding/json" |
| (...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 | 1538 |
| 1539 func (c *deployRun) Run(a subcommands.Application, args []string, env subcommand
s.Env) int { | 1539 func (c *deployRun) Run(a subcommands.Application, args []string, env subcommand
s.Env) int { |
| 1540 if !c.checkArgs(args, 1, 1) { | 1540 if !c.checkArgs(args, 1, 1) { |
| 1541 return 1 | 1541 return 1 |
| 1542 } | 1542 } |
| 1543 ctx := cli.GetContext(a, c, env) | 1543 ctx := cli.GetContext(a, c, env) |
| 1544 return c.done(deployInstanceFile(ctx, c.rootDir, args[0])) | 1544 return c.done(deployInstanceFile(ctx, c.rootDir, args[0])) |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 func deployInstanceFile(ctx context.Context, root string, instanceFile string) (
common.Pin, error) { | 1547 func deployInstanceFile(ctx context.Context, root string, instanceFile string) (
common.Pin, error) { |
| 1548 » inst, err := local.OpenInstanceFile(ctx, instanceFile, "", local.VerifyH
ash) | 1548 » inst, closer, err := local.OpenInstanceFile(ctx, instanceFile, "", local
.VerifyHash) |
| 1549 if err != nil { | 1549 if err != nil { |
| 1550 return common.Pin{}, err | 1550 return common.Pin{}, err |
| 1551 } | 1551 } |
| 1552 » defer inst.Close() | 1552 » defer closer() |
| 1553 inspectInstance(ctx, inst, false) | 1553 inspectInstance(ctx, inst, false) |
| 1554 | 1554 |
| 1555 d := local.NewDeployer(root) | 1555 d := local.NewDeployer(root) |
| 1556 defer d.CleanupTrash(ctx) | 1556 defer d.CleanupTrash(ctx) |
| 1557 | 1557 |
| 1558 // TODO(iannucci): add subdir arg to deployRun | 1558 // TODO(iannucci): add subdir arg to deployRun |
| 1559 | 1559 |
| 1560 return d.DeployInstance(ctx, "", inst) | 1560 return d.DeployInstance(ctx, "", inst) |
| 1561 } | 1561 } |
| 1562 | 1562 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 | 1620 |
| 1621 err = client.FetchInstanceTo(ctx, pin, out) | 1621 err = client.FetchInstanceTo(ctx, pin, out) |
| 1622 if err != nil { | 1622 if err != nil { |
| 1623 return common.Pin{}, err | 1623 return common.Pin{}, err |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 // Print information about the instance. 'FetchInstanceTo' already verif
ied | 1626 // Print information about the instance. 'FetchInstanceTo' already verif
ied |
| 1627 // the hash. | 1627 // the hash. |
| 1628 out.Close() | 1628 out.Close() |
| 1629 ok = true | 1629 ok = true |
| 1630 » inst, err := local.OpenInstanceFile(ctx, instanceFile, pin.InstanceID, l
ocal.SkipHashVerification) | 1630 » inst, closer, err := local.OpenInstanceFile(ctx, instanceFile, pin.Insta
nceID, local.SkipHashVerification) |
| 1631 if err != nil { | 1631 if err != nil { |
| 1632 os.Remove(instanceFile) | 1632 os.Remove(instanceFile) |
| 1633 return common.Pin{}, err | 1633 return common.Pin{}, err |
| 1634 } | 1634 } |
| 1635 » defer inst.Close() | 1635 » defer closer() |
| 1636 inspectInstance(ctx, inst, false) | 1636 inspectInstance(ctx, inst, false) |
| 1637 return inst.Pin(), nil | 1637 return inst.Pin(), nil |
| 1638 } | 1638 } |
| 1639 | 1639 |
| 1640 //////////////////////////////////////////////////////////////////////////////// | 1640 //////////////////////////////////////////////////////////////////////////////// |
| 1641 // 'pkg-inspect' subcommand. | 1641 // 'pkg-inspect' subcommand. |
| 1642 | 1642 |
| 1643 func cmdInspect() *subcommands.Command { | 1643 func cmdInspect() *subcommands.Command { |
| 1644 return &subcommands.Command{ | 1644 return &subcommands.Command{ |
| 1645 Advanced: true, | 1645 Advanced: true, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1660 | 1660 |
| 1661 func (c *inspectRun) Run(a subcommands.Application, args []string, env subcomman
ds.Env) int { | 1661 func (c *inspectRun) Run(a subcommands.Application, args []string, env subcomman
ds.Env) int { |
| 1662 if !c.checkArgs(args, 1, 1) { | 1662 if !c.checkArgs(args, 1, 1) { |
| 1663 return 1 | 1663 return 1 |
| 1664 } | 1664 } |
| 1665 ctx := cli.GetContext(a, c, env) | 1665 ctx := cli.GetContext(a, c, env) |
| 1666 return c.done(inspectInstanceFile(ctx, args[0], true)) | 1666 return c.done(inspectInstanceFile(ctx, args[0], true)) |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 func inspectInstanceFile(ctx context.Context, instanceFile string, listFiles boo
l) (common.Pin, error) { | 1669 func inspectInstanceFile(ctx context.Context, instanceFile string, listFiles boo
l) (common.Pin, error) { |
| 1670 » inst, err := local.OpenInstanceFile(ctx, instanceFile, "", local.VerifyH
ash) | 1670 » inst, closer, err := local.OpenInstanceFile(ctx, instanceFile, "", local
.VerifyHash) |
| 1671 if err != nil { | 1671 if err != nil { |
| 1672 return common.Pin{}, err | 1672 return common.Pin{}, err |
| 1673 } | 1673 } |
| 1674 » defer inst.Close() | 1674 » defer closer() |
| 1675 inspectInstance(ctx, inst, listFiles) | 1675 inspectInstance(ctx, inst, listFiles) |
| 1676 return inst.Pin(), nil | 1676 return inst.Pin(), nil |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 func inspectInstance(ctx context.Context, inst local.PackageInstance, listFiles
bool) { | 1679 func inspectInstance(ctx context.Context, inst local.PackageInstance, listFiles
bool) { |
| 1680 fmt.Printf("Instance: %s\n", inst.Pin()) | 1680 fmt.Printf("Instance: %s\n", inst.Pin()) |
| 1681 if listFiles { | 1681 if listFiles { |
| 1682 fmt.Println("Package files:") | 1682 fmt.Println("Package files:") |
| 1683 for _, f := range inst.Files() { | 1683 for _, f := range inst.Files() { |
| 1684 if f.Symlink() { | 1684 if f.Symlink() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 | 1745 |
| 1746 func (c *registerRun) Run(a subcommands.Application, args []string, env subcomma
nds.Env) int { | 1746 func (c *registerRun) Run(a subcommands.Application, args []string, env subcomma
nds.Env) int { |
| 1747 if !c.checkArgs(args, 1, 1) { | 1747 if !c.checkArgs(args, 1, 1) { |
| 1748 return 1 | 1748 return 1 |
| 1749 } | 1749 } |
| 1750 ctx := cli.GetContext(a, c, env) | 1750 ctx := cli.GetContext(a, c, env) |
| 1751 return c.done(registerInstanceFile(ctx, args[0], &c.Opts)) | 1751 return c.done(registerInstanceFile(ctx, args[0], &c.Opts)) |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 func registerInstanceFile(ctx context.Context, instanceFile string, opts *regist
erOpts) (common.Pin, error) { | 1754 func registerInstanceFile(ctx context.Context, instanceFile string, opts *regist
erOpts) (common.Pin, error) { |
| 1755 » inst, err := local.OpenInstanceFile(ctx, instanceFile, "", local.VerifyH
ash) | 1755 » inst, closer, err := local.OpenInstanceFile(ctx, instanceFile, "", local
.VerifyHash) |
| 1756 if err != nil { | 1756 if err != nil { |
| 1757 return common.Pin{}, err | 1757 return common.Pin{}, err |
| 1758 } | 1758 } |
| 1759 » defer inst.Close() | 1759 » defer closer() |
| 1760 client, err := opts.clientOptions.makeCipdClient(ctx, "") | 1760 client, err := opts.clientOptions.makeCipdClient(ctx, "") |
| 1761 if err != nil { | 1761 if err != nil { |
| 1762 return common.Pin{}, err | 1762 return common.Pin{}, err |
| 1763 } | 1763 } |
| 1764 inspectInstance(ctx, inst, false) | 1764 inspectInstance(ctx, inst, false) |
| 1765 err = client.RegisterInstance(ctx, inst, opts.uploadOptions.verification
Timeout) | 1765 err = client.RegisterInstance(ctx, inst, opts.uploadOptions.verification
Timeout) |
| 1766 if err != nil { | 1766 if err != nil { |
| 1767 return common.Pin{}, err | 1767 return common.Pin{}, err |
| 1768 } | 1768 } |
| 1769 err = client.AttachTagsWhenReady(ctx, inst.Pin(), opts.tagsOptions.tags) | 1769 err = client.AttachTagsWhenReady(ctx, inst.Pin(), opts.tagsOptions.tags) |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 // subcommand invocations look more natural. | 2214 // subcommand invocations look more natural. |
| 2215 // | 2215 // |
| 2216 // Compare: | 2216 // Compare: |
| 2217 // * Default: cipd set-ref -ref=abc -version=def package/name | 2217 // * Default: cipd set-ref -ref=abc -version=def package/name |
| 2218 // * Improved: cipd set-ref package/name -ref=abc -version=def | 2218 // * Improved: cipd set-ref package/name -ref=abc -version=def |
| 2219 // | 2219 // |
| 2220 // Much better. | 2220 // Much better. |
| 2221 func Main(params Parameters, args []string) int { | 2221 func Main(params Parameters, args []string) int { |
| 2222 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) | 2222 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) |
| 2223 } | 2223 } |
| OLD | NEW |