Skip to content

Commit

Permalink
Merge pull request #14 from fluentci-io/feat/flu-24-add-fluentci-whoa…
Browse files Browse the repository at this point in the history
…mi-command

feat: add `whoami` subcommand
  • Loading branch information
tsirysndr authored Jan 9, 2024
2 parents b99a69d + 298ffb7 commit cff8737
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.10.1
Version: 0.10.2

Description:

Expand Down Expand Up @@ -102,6 +102,7 @@ Commands:
login - Login to FluentCI
publish - Publish a pipeline to FluentCI Registry
agent - Start FluentCI Runner Agent
whoami - Show current logged in user
```
## 📚 Documentation
Expand Down
83 changes: 83 additions & 0 deletions deno.lock

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

1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
magenta,
brightMagenta,
cyan,
bold,
green,
Expand Down
7 changes: 6 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import showEnvs from "./src/cmd/env.ts";
import login from "./src/cmd/login.ts";
import publish from "./src/cmd/publish.ts";
import startAgent from "./src/cmd/agent.ts";
import whoami from "./src/cmd/whoami.ts";
import { brightGreen } from "./deps.ts";

export async function main() {
await new Command()
.name("fluentci")
.version("0.10.1")
.version("0.10.2")
.description(
`
.
Expand Down Expand Up @@ -204,6 +205,10 @@ export async function main() {
.action(async function () {
await startAgent();
})
.command("whoami", "Show current logged in user")
.action(async function () {
await whoami();
})
.parse(Deno.args);
}

Expand Down
22 changes: 22 additions & 0 deletions src/cmd/whoami.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isLogged } from "../utils.ts";
import { brightMagenta } from "../../deps.ts";

async function whoami() {
if (!(await isLogged())) {
console.log(`${brightMagenta("error")}: You are not logged in.`);
Deno.exit(1);
}

const accessToken =
Deno.env.get("FLUENTCI_ACCESS_TOKEN") ||
Deno.readTextFileSync(`${Deno.env.get("HOME")}/.fluentci/access-token`);
const id = await fetch(
`https://api.fluentci.io/validate?token=${accessToken}`
).then((res) => res.text());
const { login, name } = await fetch(`https://api.github.com/user/${id}`).then(
(res) => res.json()
);
console.log(`You are logged in as ${login} (${name})`);
}

export default whoami;

0 comments on commit cff8737

Please sign in to comment.