Skip to content

Commit

Permalink
docs(cli): update usage sections, cmd descriptions
Browse files Browse the repository at this point in the history
 - updated README getting started section to work with new cobra CLI
 - updated subcommand use section, short descriptions and long
   descriptions to provide more information
    - particularly, they now show the positional arguments in "Usage"
    - added descriptions of the positional arguments in the long description
    - these are kind of inelegant, see these issues in cobra for why
      this had to be done
        - spf13/cobra#395
        - spf13/cobra#378
  • Loading branch information
Samyak2 committed Sep 17, 2021
1 parent 7f9e68f commit fe08227
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ go install github.com/Samyak2/guntainer@latest
```
(ensure `GOBIN` is in path)

To run a container:

Confirm that the installation succeeded.
```
guntainer run <archive_of_root_FS> <command_to_run> <args_for_command>...
guntainer help
```

- `archive_of_root_FS` is an archive (tar, zip, etc.) of a root filesystem which will be `chroot`ed into
- `command_to_run` is a program *inside* the container root FS that is run (note that `PATH` is not set unless you execute a shell)
- `args_for_command` are arguments for the program (everything after the `command_to_run` is passed directly to the program)


To build a new image, first make a [`Gunfile`](#building-images) and then use:
To run a container image, use the `run` subcommand.
See [here](#run-examples) for more information and examples.
```
guntainer build Gunfile <path_to_new_image>
guntainer run --help
```

Where `Gunfile` can be replaced with the path to the Gunfile and `path_to_new_image` is the path where the generated image is saved (as a tar file)
To build a container image using a `Gunfile`, use the `build` subcommand.
See [here](#building-images) for more information and examples.
```
guntainer build --help
```

## Building images

Expand All @@ -45,7 +46,7 @@ More examples can be found [here](./examples/).

To build the image from [example_02](./examples/02_alpine_vim/), we can use:
```
guntainer build examples/02_alpine_vim/Gunfile example_02.tar
guntainer build example_02.tar examples/02_alpine_vim/Gunfile
```

This will generate an `example_02.tar` which is the newly built image with `vim` installed. Run it using:
Expand Down
11 changes: 8 additions & 3 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import (
)

var buildCommand = &cobra.Command{
Use: "build",
Use: "build [image-path] (Gunfile-path)",
Short: "Build a new container from a Gunfile",
Long: "Executes the Gunfile to build a new container image.",
Long: `Executes the Gunfile to build a new container image.
image-path: is where the resulting container image will be saved.
Gunfile-path: (optional) is the path to the Gunfile to use for building the image.`,
DisableFlagsInUseLine: true,

Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) > 1 {
core.Build(args[1], args[0])
} else {
Expand Down
13 changes: 10 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import (
)

var runCmd = &cobra.Command{
Use: "run",
Use: "run [image-path] [command]",
Short: "Run an existing container",
Long: "Run the archive of root FS as a container.",
Long: `Run the archive of root FS as a container.
image-path: is an archive (tar, zip, etc.) of a root filesystem which will be 'chroot'ed into.
command: is a program *inside* the container root FS that is run (note that PATH is not set unless you execute a shell).
Everything after the 'command' is passed as arguments directly to the command inside the container.`,
DisableFlagsInUseLine: true,

Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
core.Run(args[0], args[1], args[2:])
},
}

0 comments on commit fe08227

Please sign in to comment.