Skip to content

Commit

Permalink
Merge pull request #126 from meshcloud/feature/deno-fmt
Browse files Browse the repository at this point in the history
style: run deno fmt on cli
  • Loading branch information
JohannesRudolph authored Nov 2, 2023
2 parents bf957c0 + 65b57ff commit 0573a2c
Show file tree
Hide file tree
Showing 28 changed files with 584 additions and 322 deletions.
4 changes: 2 additions & 2 deletions cli/unipipe/blueprints/basic-handler.js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uuid } from '../deps.ts';
import { uuid } from "../deps.ts";

export const basicTransformHandler = `
/**
Expand Down Expand Up @@ -45,4 +45,4 @@ const handlers = {
};
handlers;
`
`;
5 changes: 2 additions & 3 deletions cli/unipipe/blueprints/catalog.yml.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { uuid } from '../deps.ts';
import { uuid } from "../deps.ts";

export const catalog =
`services:
export const catalog = `services:
# define a simple service offering
# for field documentation see https://github.com/openservicebrokerapi/servicebroker/blob/v2.15/spec.md#service-offering-object
- id: ${uuid.generate()} # this uuid was randomly generated using "unipipe generate uuid"
Expand Down
2 changes: 1 addition & 1 deletion cli/unipipe/blueprints/execution-script.sh.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ for filepath in **/*.main.tf; do
fi
echo "----------------------------------------------------------------"
done
`
`;
2 changes: 1 addition & 1 deletion cli/unipipe/blueprints/github-workflow.yml.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
git add .
git diff-index --quiet HEAD || git commit -m "Updating Examples"
git push
`
`;
4 changes: 2 additions & 2 deletions cli/unipipe/blueprints/terraform-handler.js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uuid } from '../deps.ts';
import { uuid } from "../deps.ts";

export const terraformTransformHandler = `
/**
Expand Down Expand Up @@ -116,4 +116,4 @@ const handlers = {
};
handlers;
`
`;
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ terraform.tfstate
# The deployment folder may contain secrets
terraform/deployment/terraform.tfstate
terraform/deployment/env.sh
`
`;
2 changes: 1 addition & 1 deletion cli/unipipe/blueprints/unipipe-osb-aci.tf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ output "unipipe_git_ssh_key" {
output "info" {
value = "UniPipe OSB is starting now. This may take a couple of minutes on Azure ACI. You can use Azure Portal to view logs of the container starting up and debug any issues. Also note that for newly deployed domains Azure ACI can take a few minutes to provide DNS."
}
`
`;
2 changes: 1 addition & 1 deletion cli/unipipe/blueprints/unipipe-osb-gcloud-cloudrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ output "unipipe_git_ssh_key" {
value = module.unipipe.unipipe_git_ssh_key
description = "UniPipe will use this key to access the git repository. You have to give read+write access on the target repository for this key."
}
`
`;
67 changes: 42 additions & 25 deletions cli/unipipe/commands/browse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { colors, Command, Input, List, prompt, Select, SelectValueOptions } from "../deps.ts";
import {
colors,
Command,
Input,
List,
prompt,
Select,
SelectValueOptions,
} from "../deps.ts";
import { OsbStatusValue } from "../osb.ts";
import { Repository } from "../repository.ts";
import { stringify } from "../yaml.ts";
Expand All @@ -9,7 +17,7 @@ export function registerBrowseCmd(program: Command) {
program
.command("browse [repo]")
.description("Interactively browse and manipulate a UniPipe OSB git repo.")
.action(async (_opts: Record<never, never>, repo: string|undefined) => {
.action(async (_opts: Record<never, never>, repo: string | undefined) => {
const repository = new Repository(repo ? repo : ".");
await browseInstances(repository);
});
Expand All @@ -32,19 +40,23 @@ async function browseInstances(repo: Repository) {
colors.dim("service: ") + colors.green(i.serviceDefinition.name),
colors.dim("plan: ") + colors.yellow(plan.name),
colors.dim("bindings: ") +
colors.brightMagenta(x.bindings.length.toString()),
colors.brightMagenta(x.bindings.length.toString()),
colors.dim("status: ") +
colors.blue(x.status?.status || "new") +
colors.red(i.deleted ? " deleted" : ""),
colors.blue(x.status?.status || "new") +
colors.red(i.deleted ? " deleted" : ""),
];

// In contrast to the list command, we do not require user input for determining which profile to use.
if (i.context.platform === "meshmarketplace") {
instanceDetails.unshift(colors.dim("project: ") + colors.white(i.context.project_id))
instanceDetails.unshift(colors.dim("customer: ") + colors.white(i.context.customer_id))
instanceDetails.unshift(
colors.dim("project: ") + colors.white(i.context.project_id),
);
instanceDetails.unshift(
colors.dim("customer: ") + colors.white(i.context.customer_id),
);
}

const name = instanceDetails.join(" ")
const name = instanceDetails.join(" ");

return { name, value: i.serviceInstanceId };
});
Expand All @@ -61,10 +73,10 @@ async function browseInstances(repo: Repository) {
colors.dim("id: ") + colors.gray(x.binding.bindingId),
// we could add binding parameters in here,
colors.dim("params: ") +
colors.green(JSON.stringify(x.binding.parameters)),
colors.green(JSON.stringify(x.binding.parameters)),
colors.dim("status: ") +
colors.blue(x.status?.status || "new") +
colors.red(x.deleted ? " deleted" : ""),
colors.blue(x.status?.status || "new") +
colors.red(x.deleted ? " deleted" : ""),
].join(" ");

return { name, value: x.binding.bindingId };
Expand All @@ -83,7 +95,7 @@ async function browseInstances(repo: Repository) {
message: "Pick a service instance",
options: instanceOptions,
search: true,
info: true
info: true,
},
{
name: "instanceCmd",
Expand All @@ -102,9 +114,8 @@ async function browseInstances(repo: Repository) {
await refreshBindingList(instanceId);
if (bindingOptions.length > 0) {
next("selectBinding");
}
else {
console.log("No bindings found for this instance!")
} else {
console.log("No bindings found for this instance!");
next("instanceCmd");
}
break;
Expand All @@ -127,7 +138,7 @@ async function browseInstances(repo: Repository) {
message: "Pick a service binding",
options: bindingOptions,
search: true,
info: true
info: true,
},
{
name: "bindingCmd",
Expand Down Expand Up @@ -198,7 +209,7 @@ async function updateInstance(repo: Repository, instanceId: string) {
async function updateBinding(
repo: Repository,
instanceId: string,
bindingId: string
bindingId: string,
) {
const { status, description } = await prompt([
{
Expand All @@ -215,8 +226,9 @@ async function updateBinding(
]);
const credentials: string[] = await List.prompt(
{
message: "Add credential `key:value` pairs. Use comma `,` to separate credentials. If you don't want to update, leave it blank.",
}
message:
"Add credential `key:value` pairs. Use comma `,` to separate credentials. If you don't want to update, leave it blank.",
},
);

// cliffy does not support whitespace in list prompt input.
Expand All @@ -225,12 +237,15 @@ async function updateBinding(
credentials.forEach((credential) => {
const colonIndex = credential.indexOf(":");
if (colonIndex === -1) {
throw new Error("Could not find colon `:` in credential `key:value` pair: " + credential);
throw new Error(
"Could not find colon `:` in credential `key:value` pair: " +
credential,
);
}
const key = credential.substring(0, colonIndex);
const value = credential.substring(colonIndex + 1);
fixedCredentials.push(key + ": " + value);
})
});

await update(repo, {
instanceId,
Expand All @@ -241,18 +256,20 @@ async function updateBinding(
});

console.log(
`Updated status of instance ${instanceId} binding ${bindingId} to '${status}' and credentials are '${fixedCredentials.length > 0 ? 'overwritten' : 'not updated'}'`
`Updated status of instance ${instanceId} binding ${bindingId} to '${status}' and credentials are '${
fixedCredentials.length > 0 ? "overwritten" : "not updated"
}'`,
);
}

async function showBinding(
repo: Repository,
instanceId: string,
bindingId: string
bindingId: string,
) {
const instance = await repo.loadInstance(instanceId);
const binding = instance.bindings.find(
(x) => x.binding.bindingId === bindingId
(x) => x.binding.bindingId === bindingId,
);

if (!binding) {
Expand All @@ -262,4 +279,4 @@ async function showBinding(
// todo: also consider printing the file paths for any "show" style command?
const p = { indent: 4 };
console.log(stringify(binding, p));
}
}
Loading

0 comments on commit 0573a2c

Please sign in to comment.