Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
add primitive for secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Dec 2, 2023
1 parent 3bb0842 commit 64d3d40
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/internal/primitive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as FileSystem from "@effect/platform/FileSystem"
// import * as AnsiRender from "@effect/printer-ansi/AnsiRender"
// import * as AnsiStyle from "@effect/printer-ansi/AnsiStyle"
// import * as Color from "@effect/printer-ansi/Color"
// import * as Doc from "@effect/printer/Doc"
import * as Schema from "@effect/schema/Schema"
import * as ConfigSecret from "effect/ConfigSecret"
import * as Effect from "effect/Effect"
import { dual, pipe } from "effect/Function"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -53,6 +50,7 @@ export type Instruction =
| Float
| Integer
| Path
| Secret
| Text

/** @internal */
Expand Down Expand Up @@ -86,6 +84,13 @@ export interface Path extends
}>
{}

/** @internal */
export interface Secret extends
Op<"Secret", {
readonly secret: ConfigSecret.ConfigSecret
}>
{}

/** @internal */
export interface Text extends Op<"Text", {}> {}

Expand Down Expand Up @@ -261,6 +266,7 @@ const getChoicesInternal = (self: Instruction): Option.Option<string> => {
case "Float":
case "Integer":
case "Path":
case "Secret":
case "Text": {
return Option.none()
}
Expand Down Expand Up @@ -323,6 +329,9 @@ const getHelpInternal = (self: Instruction): Span.Span => {
`('${self.pathType}') and path existence ('${self.pathExists}')`
)
}
case "Secret": {
return InternalSpan.text("A user-defined piece of text that is confidential.")
}
case "Text": {
return InternalSpan.text("A user-defined piece of text.")
}
Expand Down Expand Up @@ -352,6 +361,9 @@ const getTypeNameInternal = (self: Instruction): string => {
}
return self.pathType
}
case "Secret": {
return "secret"
}
case "Text": {
return "text"
}
Expand Down Expand Up @@ -432,6 +444,11 @@ const validateInternal = (
)
})
}
case "Secret": {
return attempt(value, getTypeNameInternal(self), Schema.parse(Schema.string)).pipe(
Effect.map((value) => ConfigSecret.fromString(value))
)
}
case "Text": {
return attempt(value, getTypeNameInternal(self), Schema.parse(Schema.string))
}
Expand Down Expand Up @@ -553,6 +570,14 @@ const wizardInternal = (self: Instruction, help: HelpDoc.HelpDoc): Prompt.Prompt
message: InternalHelpDoc.toAnsiText(message).trimEnd()
})
}
case "Secret": {
const primitiveHelp = InternalHelpDoc.p("Enter some text (value will be hidden)")
const message = InternalHelpDoc.sequence(help, primitiveHelp)
return InternalTextPrompt.text({
type: "password",
message: InternalHelpDoc.toAnsiText(message).trimEnd()
}).pipe(InternalPrompt.map((value) => ConfigSecret.fromString(value)))
}
case "Text": {
const primitiveHelp = InternalHelpDoc.p("Enter some text")
const message = InternalHelpDoc.sequence(help, primitiveHelp)
Expand All @@ -576,6 +601,7 @@ export const getBashCompletions = (self: Instruction): string => {
case "DateTime":
case "Float":
case "Integer":
case "Secret":
case "Text": {
return "$(compgen -f \"${cur}\")"
}
Expand Down Expand Up @@ -617,6 +643,7 @@ export const getFishCompletions = (self: Instruction): ReadonlyArray<string> =>
case "DateTime":
case "Float":
case "Integer":
case "Secret":
case "Text": {
return ReadonlyArray.make("-r", "-f")
}
Expand Down Expand Up @@ -695,6 +722,7 @@ export const getZshCompletions = (self: Instruction): string => {
}
}
}
case "Secret":
case "Text": {
return ""
}
Expand Down

0 comments on commit 64d3d40

Please sign in to comment.