This PR adds functionality to `resin sync` to try to infer what the
device uuid is as follows:
- If the argument to `resin sync` is an app, get all the devices from
that application. If there is only one, auto-select it, otherwise show
an interactive drive selection widget.
- If the argument to `resin sync` is a uuid, use it directly, without
trying to infer anything.
- If no argument is passed to `resin sync`, display an interactive
selection widget showing all your devices from all your applications.
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
Currently we log a CLI event with the passed command, however this might
include usr params, like a uuid, and therefore cause thousands of
different event names in Mixpanel.
Currently, `config generate` requires a device uuid. The command now
accepts either a uuid or an application name, and generates a
config.json accordingly.
Currently, such error will be thrown when
`resin.auth.twoFactor.challenge()` rejects, but an invalid code is not
the only thing this function can reject for.
If `updateCheckInterval` has any meanginful value, the alert will be
shown one out of ten times, or something like that, making the user
likely to miss updates.
The underlying issue is that `update-notifier`, if it detects a cached
update notification, it deletes it, and only attempts to show it back if
`updateCheckInterval` is greater than `Date.now() - lastUpdateCheck`.
A device resource needs to be registered with the API before being able
to create the `config.json` file that goes in a device.
This means thats the device image is configured and written to an
external drive (e.g: SDCard) *after* the device resource registered.
If any of the above operations fail, there will be an unitialized orphan
device living in the selected application that the user will have to
remove himself.
In my system (MBPr 13), printing the current version takes over 2
seconds:
```sh
$ time ./bin/resin version
2.4.0
./bin/resin version 1.37s user 0.19s system 73% cpu 2.130 total
```
The CLI takes almost all of these time to parse the dependency tree
before returning control over the actually called command.
To mitigate this problem, we only require the NPM dependencies a command
requires when executing such command, and thus prevent dependencies from
being required and parsed unnecessary.
After this improvement, printing the original example (`resin version`)
returns in less than a second (2x improvement):
```sh
$ time ./bin/resin version
2.4.0
./bin/resin version 0.88s user 0.09s system 102% cpu 0.938 total
```
This is useful in the scenario when the user is using the CLI in an
environment in which he/she doesn't have access to a web browser, like a
headless server or a Vagrant development environment.
Some CLI commans prompt to select an existing application, presending a
dropdown with all the application names, however it's hard to remember
which application belon to which device type, which makes it easier to
select the wrong application.
When you change the `resinUrl` config from time to time it can be
confusing to remember where you're logging in, or in which host you're
in.
Currently I have to check the configuration files/environment variables
manually or run `resin settings`.
This PR prints the detected resin url on `resin login` and `resin
whoami` so it's always clear where you are.
The command to get information about a device, `resin device` requires a
`uuid` as a parameter. Given that we don't show uuids in `resin
devices`, the user has no way to know what uuid to pass to get extra
information.
We also remove some non very used information columns from `resin
devices` to make space for the uuid.
The last part of `quickstart` feels weird. By consensus, we remove the
part that attempts to create a project directory and leave that step to
the user.
We get a weird error message from pine otherwise:
ResinRequestError: Request error: It is necessary that each app name
that is of a user (Auth), has a Length (Type) that is greater than or
equal to 4.
Current has the following problems:
- Our custom message gets printed even if the notifier doesn't contain
an update.
- The notifier box is deferred, therefore it's printed at the end of the
command. Since our custom message is printed at the beginning, it makes
no sense at all.
This allows the user to bypass the drive selection dialog.
This option can be used along with `--yes` to make the command
completely non-interactive. For example:
$ resin os initialize rpi.img 'raspberry-pi' --drive /dev/disk2 --yes
If the spinner message doesn't fit in your terminal, each spinner
position will be printed in different lines.
We mitigate this by dramatically shortenning the message.
Currently, the fact that `os initialize` requires elevated permissions
forced us to require calling commands that reuse it, such as `device
init` and `quickstart` with administrator permissions as well.
This ended up causing issues like saving images in the cache that belong
to root, or initializing git repositories that requires `sudo` to
commit.
The solution is to call `os initialize` as a child process preppending
`sudo` within `device init`.
Fixes: https://github.com/resin-io/resin-cli/issues/109
Currently, if `device init` was ran without an application argument, we
attempted to get the application name from the current directory, given
it was a git repository.
This approach led to confusions from time to time, so now we prompt the
user to select one of it's own applications from a dropdown instead of
checking the current directory in this edge case.
Fixes: https://github.com/resin-io/resin-cli/issues/197
This enforces all clients to use the Resin Settings Client version that
the SDK provides, reducing incompatibilities caused by different modules
requiring different Resin Settings Client versions.
Consider the following case:
The SDK is configured to point to staging, but the user passes a token
from production, or viceversa. Since the token is valid in a sense that
is valid JWT and contains real data, the CLI will report as a success.
The user will then get Unauthorized errors when using the API.
`update-notifier` persist its update check results in a file, which is
then read when running again the application.
If this file gets written when the application is being run as root, we
get ugly EPERM issues.
Since we're now forcing users to rely on `npm` directly for updates, we
can also get rid of plugin commands that attempt to
install/update/remove using npm programatically and require users to use
`npm` directly as well.
This commit removes the following commands:
- `plugins`
- `plugin install`
- `plugin update`
- `plugin remove`
Despite plugin related commands being removed, *the functionality that
scans for plugins and registers them remains intact*.
For this we use the `update-notifier` module with its default settings.
This module will print a nice banner prompting the user to run the
corresponding npm command to update.
We were currently building this path ourselves, hardcoding the place of
the resin local per user directory instead of relying on the foundations
that `resin-settings-client` give us.
There were two issues that prevented this command from working
correctly:
1- `Promise.delay()` is used, but `Promise` was not imported.
2- The following line had incorrect indentation (spaces instead of
tabs):
poll().nodeify(done)
Therefore CoffeeScript interpreted that the line had to be executed at
the end of the `poll()` function, causing `poll()` to never be called.
Since the public key string is long, it might wrap to lines below,
causing the table layout to break.
A quick solutio is to print the ssh key after the table.
Fixes:
- https://github.com/resin-io/resin-cli/issues/151
PubNub keeps the process alive after a history query for some reason, so
trying to print the logs history like:
$ resin logs <uuid>
Will result in the logs being printed correctly, but the process waiting
infinitely without ending.
The workaround consists in forcing `process.exit` to exit the process
with an error code zero.
Caveats:
- This workaround prevents this command to be used programatically.
Issue: https://github.com/resin-io/resin-cli/issues/14
Main changes:
- Use the `columnify` module to display the commands instead of using
manual parsing.
- Extract logic to create a string representation from an option
signature to Capitano, and reuse here.
See https://github.com/resin-io/capitano/pull/28
Some bugs were caught and fixes during the refactoring:
- In command help, if the command didn't exist, we reused default
Capitanos command not found function which uses `process.exit(1)`. This
was changed to pass a custom error to `done()`, so the command fails
correctly when using programatically.
- General help didn't call `done()` at all, thus causing problems if
using the command programatically someday.
- Add helpers.confirm() to abstract the process of asking for
confirmation.
- Add helpers.selectDeviceType() to abstract the form needed to ask for
device types.
The functions on this module are reused by app actions.
This functionality is outdated and not using anymore due to limitations
in the way it was addressed.
The module and dependencies are removed for now, and will be added back
in the future, once a better approach is planned.
We added this because we thought that knowledge of the supported device types, along with the configuration procedures was going to be encoded in the CLI.
With device specs, this is not longer the case.