Skip to content

Commit d9a51ec

Browse files
committed
package describe: added option "-c" to list content of specified package
Signed-off-by: Waldemar Kozaczuk <[email protected]>
1 parent 56241e7 commit d9a51ec

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

Documentation/generated/CLI.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ OPTIONS:
108108
--loader_image value, -l value the base loader image (default: "osv-loader")
109109
110110
111+
```
112+
113+
### capstan package describe
114+
```
115+
NAME:
116+
capstan package describe - describes the package from local repository
117+
118+
USAGE:
119+
capstan package describe [command options] [package-name]
120+
121+
OPTIONS:
122+
--content, -c show file content
123+
124+
111125
```
112126

113127
## Integrating existing packages
@@ -318,7 +332,7 @@ OPTIONS:
318332
```
319333

320334
---
321-
<sup> Documentation compiled on: 2019/10/23 02:54
335+
<sup> Documentation compiled on: 2019/10/24 03:51
322336
<br>
323337
capstan version
324338
</sup>

capstan.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,9 @@ func main() {
608608
Name: "describe",
609609
Usage: "describes the package from local repository",
610610
ArgsUsage: "[package-name]",
611+
Flags: []cli.Flag{
612+
cli.BoolFlag{Name: "content, c", Usage: "show file content"},
613+
},
611614
Action: func(c *cli.Context) error {
612615
// Name of the package is required argument.
613616
if len(c.Args()) != 1 {
@@ -620,7 +623,7 @@ func main() {
620623
packageName := c.Args()[0]
621624

622625
// Describe the package
623-
if s, err := cmd.DescribePackage(repo, packageName); err != nil {
626+
if s, err := cmd.DescribePackage(repo, packageName, c.Bool("content")); err != nil {
624627
return cli.NewExitError(err.Error(), EX_DATAERR)
625628
} else {
626629
fmt.Println(s)

cmd/package.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func ensureDirectoryStructureForFile(currfilepath string) error {
560560
}
561561

562562
// DescribePackage describes package with given name without extracting it.
563-
func DescribePackage(repo *util.Repo, packageName string) (string, error) {
563+
func DescribePackage(repo *util.Repo, packageName string, showContent bool) (string, error) {
564564
if !repo.PackageExists(packageName) {
565565
return "", fmt.Errorf("Package %s does not exist in your local repository. Pull it using "+
566566
"'capstan package pull %s'", packageName, packageName)
@@ -575,6 +575,8 @@ func DescribePackage(repo *util.Repo, packageName string) (string, error) {
575575
var cmdConf *runtime.CmdConfig
576576
var readme string
577577

578+
var content []*tar.Header
579+
578580
for {
579581
header, err := tarReader.Next()
580582
if err != nil {
@@ -608,10 +610,12 @@ func DescribePackage(repo *util.Repo, packageName string) (string, error) {
608610
return "", err
609611
}
610612
readme = string(data)
613+
} else if showContent && !absTarPathMatches(header.Name, "/meta/") {
614+
content = append(content, header)
611615
}
612616

613617
// Stop reading if we have all the information
614-
if pkg != nil && cmdConf != nil && readme != "" {
618+
if pkg != nil && cmdConf != nil && readme != "" && !showContent {
615619
break
616620
}
617621
}
@@ -667,6 +671,18 @@ func DescribePackage(repo *util.Repo, packageName string) (string, error) {
667671
s += fmt.Sprintln(readme)
668672
}
669673

674+
if showContent {
675+
s += fmt.Sprintln("PACKAGE CONTENT")
676+
for _, header := range content {
677+
s += fmt.Sprintf("%s %d %d %d %11d %s %s",
678+
header.FileInfo().Mode().String(), 0, 0, 0, header.Size, header.FileInfo().ModTime().Format(time.RFC822), header.Name)
679+
if header.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink {
680+
s += fmt.Sprintf(" -> %s", header.Linkname)
681+
}
682+
s += fmt.Sprintln("")
683+
}
684+
}
685+
670686
return s, nil
671687
}
672688

cmd/package_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (s *suite) TestDescribePackage(c *C) {
314314
ImportPackage(s.repo, s.packageDir)
315315

316316
// This is what we're testing here.
317-
descr, err := DescribePackage(s.repo, "package-name")
317+
descr, err := DescribePackage(s.repo, "package-name", false)
318318

319319
// Expectations.
320320
c.Assert(err, IsNil)

scripts/generate_cli_doc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, title, description, commands):
4242
Command('capstan package init'),
4343
Command('capstan package collect'),
4444
Command('capstan package compose'),
45+
Command('capstan package describe'),
4546
]),
4647
Group('Integrating existing packages',
4748
'These commands are useful when we intend to use package from remote repository.', [
@@ -147,4 +148,4 @@ def generate_cli_documentation():
147148

148149
print('Generating CLI documentation into %s' % RESULT_FILE)
149150
generate_cli_documentation()
150-
print('CLI documentation dumped into: %s' % RESULT_FILE)
151+
print('CLI documentation dumped into: %s' % RESULT_FILE)

0 commit comments

Comments
 (0)