Skip to content

Commit

Permalink
add requirements param in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Nov 6, 2023
1 parent 793bb88 commit 0956323
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 56 deletions.
4 changes: 4 additions & 0 deletions cmd/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func NewCmdCustom(alias string, extension extensions.Extension) (*cobra.Command,
}

func runExtension(extension extensions.Extension, input types.CommandInput, env map[string]string) error {
if err := extension.CheckRequirements(); err != nil {
return tui.Draw(tui.NewErrorPage(fmt.Errorf("missing requirements: %w", err)))
}

command, ok := extension.Command(input.Command)
if !ok {
return fmt.Errorf("command %s not found", input.Command)
Expand Down
50 changes: 47 additions & 3 deletions docs/catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Browse files and folders

### Requirements

- [`python`](https://www.python.org/)

### Commands

- `ls`: List files
Expand All @@ -37,6 +41,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Pipe your clipboard through various commands

### Requirements

- [`deno`](https://deno.com)

### Commands

- `urldecode`: URL Decode Clipboard
Expand All @@ -50,7 +58,11 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

## [GitHub](https://github.com/pomdtr/sunbeam/tree/main/extensions/github.ts)

undefined
Search GitHub repositories

### Requirements

- [`deno`](https://deno.com)

### Commands

Expand All @@ -69,6 +81,11 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Manage your tailscale devices

### Requirements

- [`deno`](https://deno.com)
- [`tailscale`](https://tailscale.com)

### Commands

- `list-devices`: Search My Devices
Expand Down Expand Up @@ -100,6 +117,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Manage your gists

### Requirements

- [`deno`](https://deno.com)

### Commands

- `list`: List Gists
Expand All @@ -115,7 +136,11 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

## [Bitwarden Vault](https://github.com/pomdtr/sunbeam/tree/main/extensions/bitwarden.sh)

List your Bitwarden passwords
Search your Bitwarden passwords

### Requirements

- [`bw`](https://bitwarden.com/help/article/cli/)

### Commands

Expand All @@ -131,6 +156,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Manage your VS Code projects

### Requirements

- [`deno`](https://deno.com)

### Commands

- `list-projects`: List Projects
Expand Down Expand Up @@ -176,6 +205,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Browse TLDR Pages

### Requirements

- [`tldr`](https://dbrgn.github.io/tealdeer/installing.html)

### Commands

- `list`: Search Pages
Expand Down Expand Up @@ -207,6 +240,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Manage your RSS feeds

### Requirements

- [`deno`](https://deno.com)

### Commands

- `show`: Show a feed
Expand All @@ -221,6 +258,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Browse Hacker News

### Requirements

- [`deno`](https://deno.com)

### Commands

- `browse`: Show a feed
Expand Down Expand Up @@ -250,6 +291,10 @@ sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/

Manage your raindrop bookmarks

### Requirements

- [`deno`](https://deno.com)

### Commands

- `search-bookmarks`: Search Bookmarks
Expand All @@ -259,4 +304,3 @@ Manage your raindrop bookmarks
```
sunbeam extension install https://raw.githubusercontent.com/pomdtr/sunbeam/main/extensions/raindrop.ts
```

17 changes: 7 additions & 10 deletions extensions/bitwarden.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
if [ $# -eq 0 ]; then
sunbeam query -n '{
title: "Bitwarden Vault",
description: "List your Bitwarden passwords",
description: "Search your Bitwarden passwords",
requirements: [
{ name: "bw", link: "https://bitwarden.com/help/article/cli/" }
],
commands: [
{
name: "list-passwords",
Expand All @@ -15,20 +18,14 @@ if [ $# -eq 0 ]; then
exit 0
fi

# check for dependencies
if ! command -v bkt &> /dev/null; then
echo "bkt could not be found"
exit 1
fi

if ! command -v bw &> /dev/null; then
echo "bw could not be found"
if [ -z "$BW_SESSION" ]; then
echo "Please set BW_SESSION environment variable"
exit 1
fi

COMMAND=$(echo "$1" | jq -r '.command')
if [ "$COMMAND" = "list-passwords" ]; then
bkt --ttl 24h --stale 1h -- bw --nointeraction list items --session "$BW_SESSION" | sunbeam query 'map({
bw --nointeraction list items --session "$BW_SESSION" | sunbeam query 'map({
title: .name,
subtitle: (.login.username // ""),
actions: [
Expand Down
1 change: 1 addition & 0 deletions extensions/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{
"title": "File Browser",
"description": "Browse files and folders",
"requirements": [{"name": "python", "link": "https://www.python.org/"}],
"commands": [
{
"name": "ls",
Expand Down
8 changes: 7 additions & 1 deletion extensions/gist.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env deno run -A

import { Octokit } from "https://esm.sh/[email protected]?dts";
import * as sunbeam from "npm:[email protected].18"
import * as sunbeam from "npm:[email protected].19"

if (Deno.args.length === 0) {
const manifest: sunbeam.Manifest = {
title: "Gist",
description: "Manage your gists",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
commands: [
{
name: "list",
Expand Down
9 changes: 8 additions & 1 deletion extensions/github.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env deno run -A

import type * as sunbeam from "npm:[email protected].18";
import type * as sunbeam from "npm:[email protected].19";
import * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";

if (Deno.args.length == 0) {
const manifest: sunbeam.Manifest = {
title: "GitHub",
description: "Search GitHub repositories",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
commands: [
{
title: "Search Repositories",
Expand Down
10 changes: 8 additions & 2 deletions extensions/hackernews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import Parser from "npm:rss-parser";
import { formatDistance } from "npm:date-fns";
import * as sunbeam from "npm:[email protected].15"
import * as sunbeam from "npm:[email protected].19"

if (Deno.args.length == 0) {
const manifest: sunbeam.Manifest = {
title: "Hacker News",
description: "Browse Hacker News",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
root: [
{
title: "Front Page",
Expand Down Expand Up @@ -40,7 +46,7 @@ if (Deno.args.length == 0) {
Deno.exit(0);
}

const payload = JSON.parse(Deno.args[0]) as sunbeam.CommandInput;
const payload = JSON.parse(Deno.args[0]) as sunbeam.Payload;
if (payload.command == "browse") {
const { topic } = payload.params as { topic: string };
const feed = await new Parser().parseURL(`https://hnrss.org/${topic}?description=0&count=25`);
Expand Down
8 changes: 7 additions & 1 deletion extensions/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env deno run -A
import * as sunbeam from "npm:[email protected].16"
import * as sunbeam from "npm:[email protected].19"
import * as clipboard from "https://deno.land/x/[email protected]/mod.ts";


if (Deno.args.length == 0) {
const manifest: sunbeam.Manifest = {
title: "Pipe Commands",
description: "Pipe your clipboard through various commands",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
commands: [
{
name: "urldecode",
Expand Down
10 changes: 8 additions & 2 deletions extensions/raindrop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env -S deno run -A
import * as sunbeam from "npm:[email protected].15"
import * as sunbeam from "npm:[email protected].19"

if (Deno.args.length === 0) {
const manifest: sunbeam.Manifest = {
title: "Raindrop",
description: "Manage your raindrop bookmarks",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
commands: [
{
title: "Search Bookmarks",
Expand All @@ -22,7 +28,7 @@ if (!raindropToken) {
throw new Error("RAINDROP_TOKEN is not set");
}

const payload = JSON.parse(Deno.args[0]) as sunbeam.CommandInput;
const payload = JSON.parse(Deno.args[0]) as sunbeam.Payload;
if (payload.command == "search-bookmarks") {
const resp = await fetch("https://api.raindrop.io/rest/v1/raindrops/0", {
headers: {
Expand Down
10 changes: 8 additions & 2 deletions extensions/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import Parser from "npm:rss-parser";
import { formatDistance } from "npm:date-fns";
import * as sunbeam from "npm:[email protected].15"
import * as sunbeam from "npm:[email protected].19"

if (Deno.args.length == 0) {
const manifest: sunbeam.Manifest = {
title: "RSS",
description: "Manage your RSS feeds",
requirements: [
{
name: "deno",
link: "https://deno.com"
}
],
commands: [
{
name: "show",
Expand All @@ -29,7 +35,7 @@ if (Deno.args.length == 0) {
Deno.exit(0);
}

const payload = JSON.parse(Deno.args[0]) as sunbeam.CommandInput;
const payload = JSON.parse(Deno.args[0]) as sunbeam.Payload;
if (payload.command == "show") {
const params = payload.params as { url: string };
const feed = await new Parser().parseURL(params.url);
Expand Down
14 changes: 12 additions & 2 deletions extensions/tailscale.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/usr/bin/env -S deno run -A
import type * as sunbeam from "npm:[email protected].15";
import type * as sunbeam from "npm:[email protected].19";

if (Deno.args.length == 0) {
const manifest: sunbeam.Manifest = {
title: "Tailscale",
description: "Manage your tailscale devices",
requirements: [
{
name: "deno",
link: "https://deno.com"
},
{
name: "tailscale",
link: "https://tailscale.com"
}
],
commands: [
{
name: "list-devices",
Expand Down Expand Up @@ -38,7 +48,7 @@ type Device = {
Online: boolean;
}

const payload = JSON.parse(Deno.args[0]) as sunbeam.CommandInput;
const payload = JSON.parse(Deno.args[0]) as sunbeam.Payload;

if (payload.command == "list-devices") {
const command = new Deno.Command("tailscale", { args: ["status", "--json"] });
Expand Down
9 changes: 3 additions & 6 deletions extensions/tldr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if [ $# -eq 0 ]; then
{
title: "Browse TLDR Pages",
description: "Browse TLDR Pages",
requirements: [
{ name: "tldr", link: "https://dbrgn.github.io/tealdeer/installing.html" }
],
# each command can be called through the cli
commands: [
{ name: "list", mode: "list", title: "Search Pages" },
Expand All @@ -19,12 +22,6 @@ if [ $# -eq 0 ]; then
exit 0
fi

# check if tldr is installed
if ! command -v tldr >/dev/null 2>&1; then
echo "tldr is not installed. Please install it from https://dbrgn.github.io/tealdeer/installing.html"
exit 1
fi

COMMAND=$(echo "$1" | jq -r '.command')
if [ "$COMMAND" = "list" ]; then
tldr --list | sunbeam query -R '{
Expand Down
Loading

0 comments on commit 0956323

Please sign in to comment.