File: 03_command_line.md

package info (click to toggle)
ignition-fuel-tools 7.0.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,176 kB
  • sloc: cpp: 9,601; ruby: 395; sh: 131; ansic: 38; makefile: 8
file content (148 lines) | stat: -rw-r--r-- 4,884 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
\page cmdline Command Line Tools

Next Tutorial: \ref cppapi

## Overview

The `ign fuel` command line tool provides a convenient way to handle Ignition
Fuel resources from a terminal.

## List resources

Let's use the command line to list resources available in a web server.
We can do that by running the `ign fuel list` command and pass it the resource
type, such as `model` or `world` as follows:

`ign fuel list -t world`

You should see a list such as:

```
Fetching world list from https://fuel.ignitionrobotics.org...
Received world list (took 350ms).
https://fuel.ignitionrobotics.org
├── OpenRobotics
│   ├── Empty
│   └── Shapes
└── chapulina
    └── Shapes copy
```

By default, Fuel will list resources from all the servers listed in your
`config.yaml` file. See the
[configuration tutorial](https://ignitionrobotics.org/tutorials/fuel_tools/1.0/md__data_ignition_ign-fuel-tools_tutorials_02_configuration.html)
for more details.

> **Tip**: If you want to see resources from a different Fuel server, add it to
`config.yaml` to and re-run the list command to see resources from both servers!

There are a few other options on the command, run the help to see all of them:

`ign fuel list --help`

### Raw output

One of them is the `--raw` option, which tells the command to print the output in
a way that's easier for scripts to parse. For example, try:

`ign fuel list -t world -r`

And you'll get a list of the world URLs similar to the one below:

```
https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty
https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Shapes
https://fuel.ignitionrobotics.org/1.0/chapulina/worlds/Shapes%20copy
```

### By owner

It's also possible to only list resources belonging to a given user, using the
`--owner` flag. Try for example:

`ign fuel list -t model -o OpenRobotics`

## Download resources

The command line tool also allows downloading resources from a web server to your
computer. We use the `ign fuel download` tool for this.

We learned above how to get resource URLs. Now we can use these URLs to download
them. For example, try:

`ign fuel download -v 4 -u https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty`

Note that we passed the `-v 4` option so we get a verbose output. You should see something like:

```
Downloading world:
  Name: Empty
  Owner: OpenRobotics
  Server:
    URL: https://fuel.ignitionrobotics.org
    Version: 1.0

[Msg] Downloading world [fuel.ignitionrobotics.org/OpenRobotics/worlds/Empty]
[Msg] Saved world at:
  /home/louise/.ignition/fuel/fuel.ignitionrobotics.org/OpenRobotics/worlds/Empty/1
Download succeeded.
```

If the model is privated you can create a config file with your token. For example, create a file
`/tmp/my_config.yaml` with the following content and edit your token:

```yaml
---
# The list of servers.
servers:
  -
    url: https://fuel.ignitionrobotics.org
    private-token: <your private token>
```

Then try to download the model:

```bash
ign fuel download -v 4 -u https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty -c /tmp/my_config.yaml
```

Worlds downloaded with the tool get conveniently organized into the same
directory, which we call the "local cache". The path is broken down as follows:

`<local cache path>/<server URL>/<owner name>/<resource type>/<resource name>/<version number>`

> **Tip**: You can change the local cache path in `config.yaml`.

> **Tip**: You can also use other tools such as `wget` to download a zipped file of a world, just add `.zip` to the end of the URL, for example: `wget https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty.zip`.

## Edit resources

It's possible to edit a resource from the command line after it has been
uploaded to Fuel. Edit functionality is available through the `edit`
sub-command. You can access the list of edit options using:

```
ign fuel edit -h
```

You must be the resource owner, or an authorized member of the organization that owns the resource, in order to edit the resource. This in turn means you must use the `--header 'Private-token: YOUR_TOKEN'` option with the `edit` sub-command.

### Change resource privacy

The edit sub-command supports toggling a resource's status between pubic and
private. A public resource is accessible to everyone, while a private
resource is accessible only to the owner. The owner of a resource could be
an organization, in which case all members of the organization would have
access.

Use the `-p` option to make a resources private. For example:

```
ign fuel edit -p -u https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty --header 'Private-token: YOUR_TOKEN'
```

Use the `-b` option to make a resource public. For example:

```
ign fuel edit -b -u https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty --header 'Private-token: YOUR_TOKEN'
```