28 Commits

Author SHA1 Message Date
35d1f12213 make podman pod inspect output a json array
Just like all the other inspect commands that accept multiple args we
should just make podman pod inspect output a json array.
This makes the code more consistent and removes the extra workaround
which was needed before to support this.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-02-05 17:26:55 +01:00
de92db0c81 man pages and command help: clean up descriptions
Short description in man pages:
* Use imperative form

Command help (cobra.Command.Short):
* Capitalize first letter
* Use imperative form
* Remove ending full stop when the short description
  only contains one sentence without any commas

Command help (cobra.Command.Long):
* Capitalize first letter unless the sentence starts
  with a command "podman command ..."
* Use imperative form when the long description is
  identical or almost identical to the short description.
  This modification was only done in a few places.

Command tables:
* Use imperative form in the "Description" column

[NO NEW TESTS NEEDED]

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2023-05-28 18:57:43 +02:00
d10e77e1bc fix podman pod inspect to support multiple pods
Just like the other inspect commands `podman pod inspect p1 p2` should
return the json for both.

To correctly implement this we follow the container inspect logic, this
allows use to reuse the global inspect command.
Note: To not break the existing single pod output format for podman pod
inspect I added a pod-legacy inspect type. This is only used to make
sure we will print the pod as single json and not an array like for the
other commands. We cannot use the pod type since podman inspect --type
pod did return an array and we should not break that as well.

Fixes #15674

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-09-08 10:28:42 +02:00
e8adec5f41 cmd/podman: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-06-30 12:58:57 +02:00
0d9f190280 shell completion --format: use structs by reference
For the AutocompleteFormat function we expect the correct template
struct which is used in the golang template. The function can handle
both struct and pointer to a struct. Using the reference is more
efficient since it doe snot have to copy the whole struct.

Also change some structs to use he actual type from the template instead
of some nested one to make sure it has to correct fields.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-28 18:12:17 +02:00
bd09b7aa79 bump go module to version 4
Automated for .go files via gomove [1]:
`gomove github.com/containers/podman/v3 github.com/containers/podman/v4`

Remaining files via vgrep [2]:
`vgrep github.com/containers/podman/v3`

[1] https://github.com/KSubedi/gomove
[2] https://github.com/vrothberg/vgrep

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-18 12:47:07 +01:00
d35aa3f293 Refactor podman pods to report.Formatter
[NO NEW TESTS NEEDED]

Support better compatibility output for podman pods commands

See #10974
Depends on containers/common#831

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-12-06 10:51:29 -07:00
61792de36e Refactor podman image command output
Leverage new report.Formatter allowing better compatibility from
podman command output.

Follow on PR's will cover containers, etc.

See #10974

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-12-02 09:07:27 -07:00
6888b061d0 inspect: printTmpl must Flush writer
Flush should be called after the last call to Write to ensure that any data buffered in the Writer is written to output.
Any incomplete escape sequence at the end is considered complete for formatting purposes.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-09-09 16:37:24 +05:30
bd9987239d Scrub podman commands to use report package
Refactor podman commands that have drifted from using
c/common report pkg. Report pkg is needed to implement
go template functions.

Removed obsolete code from podman which exists in c/common.

Latest template library added default newlines and method to
remove them. Incorporated needed changes in c/common PR below.

Depends on https://github.com/containers/common/pull/624
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1855983

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-06-16 16:53:48 -07:00
33944cefe7 [Techinal Debt] Cleanup ABI vs. Tunnel CLI commands
[NO TESTS NEEDED]

This commit cleans up two issues:
* Most commands support all EngineModes so default to that. Let
  outlayers declare their intent.
* Use cobra.Annotations to set supported EngineMode. This simplies
  instantiating commands as there is now one method to communicate a
  commands requirements rather than two.
* Combined aliased commands into one file
* Fixed aliased commands where Args field did not match
* Updated examples in README.md for writing commands
* Remove redundant flag DisableFlagsInUseLine in cobra.Command
  initialization.

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-05-27 11:40:43 -07:00
d81021ed26 Add go template shell completion for --format
The --format flags accepts go template strings. I use this often but I
consistently forget the field names. This commit adds a way to provide
shell completion for the --format flag. It works by automatically
receiving the field names with the reflect package from the given
struct. This requires almost no maintenance since this ensures that we
always use the correct field names. This also works for nested structs.

```
$ podman ps --format "{{.P"
{{.Pid}}      {{.PIDNS}}    {{.Pod}}      {{.PodName}}  {{.Ports}}
```

NOTE: This only works when you use quotes otherwise the shell does not
provide completions. Also this does not work for fish at the moment.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-04-22 00:31:08 +02:00
5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
78c8a87362 Enable whitespace linter
Use the whitespace linter and fix the reported problems.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-11 23:01:56 +01:00
8452b768ec Fix problems reported by staticcheck
`staticcheck` is a golang code analysis tool. https://staticcheck.io/

This commit fixes a lot of problems found in our code. Common problems are:
- unnecessary use of fmt.Sprintf
- duplicated imports with different names
- unnecessary check that a key exists before a delete call

There are still a lot of reported problems in the test files but I have
not looked at those.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-01-12 16:11:09 +01:00
b5d1d89a37 Add shell completion with cobra
Allow automatic generation for shell completion scripts
with the internal cobra functions (requires v1.0.0+).

This should replace the handwritten completion scripts
and even adds support for fish. With this approach it is
less likley that completions and code are out of sync.

We can now create the scripts with
- podman completion bash
- podman completion zsh
- podman completion fish

To test the completion run:
source <(podman completion bash)

The same works for podman-remote and podman --remote and
it will complete your remote containers/images with
the correct endpoints values from --url/--connection.

The completion logic is written in go and provided by the
cobra library. The completion functions lives in
`cmd/podman/completion/completion.go`.

The unit test at cmd/podman/shell_completion_test.go checks
if each command and flag has an autocompletion function set.
This prevents that commands and flags have no shell completion set.

This commit does not replace the current autocompletion scripts.

Closes #6440

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-11-12 11:38:31 +01:00
2bd920b005 Merge pull request #8077 from jwhonce/wip/report
Refactor podman to use c/common/pkg/report
2020-10-21 17:59:56 -04:00
bab3cda0e8 Refactor podman to use c/common/pkg/report
All formatting for containers stack moved into one package
The does not correct issue with headers when using custom tables

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-10-21 08:16:52 -07:00
980b1e87d4 Switch use of Flags to Options
Want to have man pages match commands, since we have lots of printed
man pages with using Options, we will change the command line to use
Options in --help.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-21 08:37:57 -04:00
bddd5580ab Fix indentation for podman pod inspect
Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-10-14 13:55:16 -04:00
3cca814eb3 Restore --format 'table...' to commands
* podman xyz inspect

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-10-08 07:42:07 -07:00
2583948f72 Usability: prevent "-l" with arguments
Add new system check confirming that "podman foo -l arg"
throws an error; and fix lots of instances where code
was not doing this check.

I'll probably need to add something similar for --all but
that can wait.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-09-14 15:49:28 -06:00
a5e37ad280 Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
6fb5f01c73 Fixes --remote flag issues
* --remote, --url and --identity are now anchored to podman command.
  Subcommands should no longer have issues
* TraverseChildren now set to V1 expectations
* Latest flag now has helper function. Now has consistent usage.
* IsRemote() uses cobra parser to determin if --remote is given
* Moved validation functions from parser pkg to validate pkg
*

Fixes #6598
Fixes #6704

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-06-26 17:09:24 -07:00
1f8a78747a Add --format to pod inspect
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
2020-05-27 09:48:38 +03:00
b21a5b7ff4 Provide a json variable pointing to a configured json API
* All commands now using the same instance of json API
* `json` variable created in each package to prevent `encoding/json`
  from being re-introduced

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-04-21 07:56:10 -07:00
241326a9a8 Podman V2 birth
remote podman v1 and replace with podman v2.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-16 15:53:58 -05:00