Skip to content

Commit

Permalink
feat: finish nix packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinLoeper committed Mar 28, 2024
1 parent 4a47662 commit 60509a0
Show file tree
Hide file tree
Showing 13 changed files with 1,254 additions and 754 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ A command-line utility to select S3 keys interactively.

### Nix

`nix profile install github:nesto-software/s3-browser-cli`

## Synopsis

`s3select [options]`
Expand All @@ -29,9 +31,9 @@ Note: The *objectPrefix* must be a *folder*, i.e. a key's prefix not the full ob

```bash
TMP_FILE=$(mktemp)
s3select 3>$TMP_FILE
s3select --redirect 3>$TMP_FILE

SELECTED_S3_KEY=$(echo $TMP_FILE | jq -r '.prefix')
SELECTED_S3_KEY=$(cat $TMP_FILE | jq -r '.prefix')
```

**Why is getting the output so difficult?**
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import inquirer from "inquirer";
import inquirer_s3 from "inquirer-s3";
import inquirer_s3 from "@nesto-software/inquirer-s3";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import fs from "fs";
Expand Down Expand Up @@ -67,7 +67,7 @@ yargs(hideBin(process.argv))
// check if user wants to access the output programmatically
if (argv.redirect) {
fd3.write(out);
console.log("Wrote result to fd3.");
console.log("Wrote result to fd3. If you do not poll fd3, the program hangs idefinitely.");
} else {
console.log(out);
}
Expand Down
2 changes: 2 additions & 0 deletions outputs/out/bin/s3select
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /nix/store/5lr5n3qa4day8l1ivbwlcby2nknczqkq-bash-5.2p26/bin/bash -e
exec -a "$0" "/nix/store/rlv9fcq70pniyrm3xy21wgk5rdhdh12h-nodejs-20.11.1/bin/node" /home/mloeper/nesto/repos/nesto-software/s3-browser-cli/outputs/out/index.js "$@"
76 changes: 76 additions & 0 deletions outputs/out/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node
import inquirer from "inquirer";
import inquirer_s3 from "inquirer-s3";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import fs from "fs";

inquirer.registerPrompt('s3-object', inquirer_s3);

// workaround, see README
const fd3 = fs.createWriteStream(null, {fd: 3});

// note: move into nix env
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';

yargs(hideBin(process.argv))
.command('*', 'start the interactive s3 key selection', (yargs) => {
return yargs
.option('bucket', {
type: "string",
describe: 'A bucket to pre-select. When specifying the bucket parameter with the name of a valid S3 account owned by your AWS account, the inquirer-s3 module will start to browse at the root of this bucket'
})
.option('objectPrefix', {
type: "string",
alias: "key",
describe: "An S3 object prefix indicating where you'd like to start the browsing inside a bucket",
})
.option('enableFolderSelect', {
type: "boolean",
alias: "folders",
describe: " If set, the user is allowed to select an S3 *folder* prefix as a valid result, default false"
})
.option('enableFileObjectSelect', {
type: "boolean",
alias: "files",
describe: "If set, the user is allowed to select an S3 object (*files*) as a valid result, default true",
})
.option('enableOtherBuckets', {
type: "boolean",
alias: "allow-switch",
describe: "If set, the user should be allowed to navigate to buckets other than the bucket parameter specified, default true",
})
.option('redirect', {
type: "boolean",
default: false,
describe: "Use fd3 to write the command output instead of fd1 - ideal for programmatic access such as using jq",
})
}, async (argv) => {
const res = await inquirer.prompt([{
type: 's3-object',
name: 'result',
message: 'Which S3 object would you like to select?',
bucket: argv.bucket,
objectPrefix: argv.objectPrefix,
enableFolderSelect: argv.enableFolderSelect,
enableFileObjectSelect: argv.enableFileObjectSelect,
enableOtherBuckets: argv.enableOtherBuckets,
}]);

let out = "";
if (res && res.result) {
out = JSON.stringify(res.result);
} else {
out = "{}";
}

// check if user wants to access the output programmatically
if (argv.redirect) {
fd3.write(out);
console.log("Wrote result to fd3.");
} else {
console.log(out);
}
})
.strict()
.parse();
1 change: 1 addition & 0 deletions outputs/out/node_modules
26 changes: 26 additions & 0 deletions outputs/out/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "s3-browser-cli",
"version": "1.0.1",
"type": "module",
"description": "An s3 browser cli binary to select files interactively",
"main": "index.js",
"author": "Martin Löper <[email protected]>",
"repository": "https://github.com/nesto-software/s3-browser-cli",
"license": "MIT",
"bin": {
"s3select": "./index.js"
},
"scripts": {
"start": "node index.js",
"rjson": "rjson"
},
"dependencies": {
"inquirer": "^1.2.3",
"@nesto-software/inquirer-s3": "1.0.2",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/inquirer": "^7.3.3",
"@types/yargs": "^17.0.32"
}
}
Loading

0 comments on commit 60509a0

Please sign in to comment.