-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from fluentci-io/feat/flu-24-add-fluentci-whoa…
…mi-command feat: add `whoami` subcommand
- Loading branch information
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { | ||
magenta, | ||
brightMagenta, | ||
cyan, | ||
bold, | ||
green, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |