Skip to content

Commit

Permalink
feat: readme cleanup (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollorion authored Feb 20, 2022
1 parent 06f228e commit b8c4c74
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,38 @@ etc, etc, etc.
All flights are defined in `extension/flights.ts`.

## Logical Flights
Logical flights are, I guess you could call, "smart links".
They arent hardcoded into this repository and use logic to determine where you want to go.
You can set defaults for anything within a logical flight.
Logical flights are smarter than a standard flight because you can set defaults for any variable of the flight.

Defaults can be set/unset via:
- `fly set {key} {value}`
- `fly unset {key}`

### How it works
Look at the `gh` logical flight as an example. Its logic is as follows: `https://github.com/${gh-org}/${repo}`.

If no defaults are specified, the extension will assume you will pass in at least 2 parameters to the flight.
`fly hg Apollorion manifests.io` is calculated positionally in this case. `Apollorion` will replace `${gh-org}` and `manifests.io` will replace `${repo}`.
`fly gh Apollorion manifests.io` is calculated positionally. `Apollorion` (the first parameter) will replace `${gh-org}` (the first variable)
and `manifests.io` (the second parameter) will replace `${repo}` (the second variable).
Which will fly to `https://github.com/Apollorion/manifests.io`.

You can, optionally, set a default for any parameter in a logical flight.
`fly set gh-org Apollorion` will set the default for `gh-org` to `Apollorion`.
Now, when you fly the `gh` flight, it will first replace `${gh-org}` with `Apollorion` and then any remaining parameters will be replaced positionally.
You can, optionally, set a default for any variable in a logical flight.
`fly set gh-org Apollorion` will set the default for `gh-org` to `Apollorion`.
Now, when you fly the `gh` flight, it will first replace `${gh-org}` with `Apollorion` and then any remaining parameters will be replaced positionally, like above.
So you could do `fly gh manifests.io` and it will fly to `https://github.com/Apollorion/manifests.io`.

Note: ANY unset parameters will be replaced positionally, in order.
If you have a logical flight that is defined as `https://my.com/{$thing1}/{$thing2}/{$thing3}`, and you only set the default for `thing1`.
The extension will expect you to pass in 2 parameters at flight time, otherwise a default flight will be used or an error will be thrown.
The extension will expect you to pass in 2 parameters at flight time, otherwise a default flight will be used or an error will be thrown.
`fly my.com test1 test2` will fly to `https://my.com/{thing1 default}/test1/test2/`.
`fly my.com test` will either go to a defined default flight or throw an error.

# Custom flight repos
You can host a custom flight repo and point the extension to it. This will allow you to define standard and logical flights without contributing to this project.

An example repo doc is here: `https://apollorion.com/flight_repo_named.json`
Repos can be managed via:
- `fly repo set {name} {url}`
- `fly repo unset {name}`
- `fly repo update` - this is what actually fetch's flight data. Akin to `apt update`.

The custom flight repo has 2 requirements.
1. The `Access-Control-Allow-Origin: *` header is present (this is a chrome requirement)
Expand All @@ -82,34 +89,22 @@ interface CustomFlightRepo {
}
}
```

To use the custom flight repo, just run `fly repo set $name $url` then `fly repo update`. You can unset this repo at anytime via `fly repo unset $name`.
`fly repo update` will fetch the contents of the repository.
An example repo doc is here: `https://apollorion.com/flight_repo_named.json`

ex:
1. `fly repo set apollorion https://apollorion.com/flight_repo_named.json`
2. `fly repo update`
3. `fly repo unset apollorion`

Note: Logical flights take precedence over standard flights, in a custom flight repo. If a flight is defined in this extension as a logical flight, and you want to simplify it, you will want to
define it as a logical flight in your repo. Otherwise, your flight will not work.

# Devving this repo

Startup the dev server via `./dev.sh`.
You need to `load unpacked` the extension in the `extension/dist` dir after building at least once.

I havent found a work around yet, but whenever you make a change you need to refresh the extension in `chrome://extensions`.


## Logical Flights
Say a users query is `fly gh Apollorion manifests.io`

The example logic above will match `gh`, split `Apollorion manifests.io` into `$1` = `Apollorion` and `$2` = `manifests.io`.
The logic defined in `extension/flights.ts` for `gh` is `https://github.com/$1/$2` which resolves to `https://github.com/Apollorion/manifests.io`.

If your logical flight doesnt need to be very smart you can simply add the flight name (`gh` in the above example) to the`logicalFlights` const in `extension/main.ts`.
The extension will "just work" if you expect users to always type the full query in the extension.
As an example, the `aws` flight automatically builds the correct query without any special logic because it expects the user to type the full query every time.

If you logical flight does need some custom logic, you can build that into `extension/main.ts`. I'd suggest using `gh` as an example.

I haven't found a work around yet, but whenever you make a change you need to refresh the extension in `chrome://extensions`.

# Alfred
If youre looking for the alfred implementation of fly, checkout https://github.com/Apollorion/fly-alfred
If you're looking for the alfred implementation of fly, checkout https://github.com/Apollorion/fly-alfred (depreciated).

0 comments on commit b8c4c74

Please sign in to comment.