Skip to content

Commit

Permalink
Update APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 24, 2024
1 parent 1eb5865 commit 3b27de7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
29 changes: 21 additions & 8 deletions crates/pdk-api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@ api_struct!(
pub struct ExecutableConfig {
/// The file to execute, relative from the tool directory.
/// Does *not* support virtual paths.
///
/// The following scenarios are powered by this field:
/// - Is the primary executable.
/// - For primary and secondary bins, the source file to be symlinked,
/// and the extension to use for the symlink file itself.
/// - For primary shim, this field is ignored.
/// - For secondary shims, the file to execute.
#[serde(skip_serializing_if = "Option::is_none")]
pub exe_path: Option<PathBuf>,

Expand All @@ -311,6 +304,10 @@ api_struct!(
#[serde(skip_serializing_if = "Option::is_none")]
pub parent_exe_name: Option<String>,

/// Whether this is the primary executable or not.
#[serde(skip_serializing_if = "is_false")]
pub primary: bool,

/// Custom args to prepend to user-provided args within the generated shim.
#[serde(skip_serializing_if = "Option::is_none")]
pub shim_before_args: Option<StringOrVec>,
Expand All @@ -333,6 +330,14 @@ impl ExecutableConfig {
}
}

pub fn new_primary<T: AsRef<str>>(exe_path: T) -> Self {
Self {
exe_path: Some(PathBuf::from(exe_path.as_ref())),
primary: true,
..ExecutableConfig::default()
}
}

pub fn with_parent<T: AsRef<str>, P: AsRef<str>>(exe_path: T, parent_exe: P) -> Self {
Self {
exe_path: Some(PathBuf::from(exe_path.as_ref())),
Expand All @@ -346,8 +351,14 @@ api_struct!(
/// Output returned by the `locate_executables` function.
#[serde(default)]
pub struct LocateExecutablesOutput {
/// Configures executable information to be used as proto bins/shims.
/// The map key will be the name of the executable file.
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
pub exes: FxHashMap<String, ExecutableConfig>,

/// Relative directory path from the tool install directory in which
/// pre-installed executables can be located.
/// pre-installed executables can be located. This directory path
/// will be used during `proto active`, but not for bins/shims.
#[serde(skip_serializing_if = "Option::is_none")]
pub exes_dir: Option<PathBuf>,

Expand All @@ -363,11 +374,13 @@ api_struct!(

/// Configures the primary/default executable to create.
/// If not provided, a primary shim and binary will *not* be created.
#[deprecated(note = "Use `exes` instead.")]
#[serde(skip_serializing_if = "Option::is_none")]
pub primary: Option<ExecutableConfig>,

/// Configures secondary/additional executables to create.
/// The map key is the name of the shim/binary file.
#[deprecated(note = "Use `exes` instead.")]
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
pub secondary: FxHashMap<String, ExecutableConfig>,
}
Expand Down
17 changes: 9 additions & 8 deletions package/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ export interface ExecutableConfig {
/**
* The file to execute, relative from the tool directory.
* Does *not* support virtual paths.
*
* The following scenarios are powered by this field:
* - Is the primary executable.
* - For primary and secondary bins, the source file to be symlinked,
* and the extension to use for the symlink file itself.
* - For primary shim, this field is ignored.
* - For secondary shims, the file to execute.
*/
exePath?: string | null;
/** Do not symlink a binary in `~/.proto/bin`. */
Expand All @@ -279,6 +272,8 @@ export interface ExecutableConfig {
noShim?: boolean;
/** The parent executable name required to execute the local executable path. */
parentExeName?: string | null;
/** Whether this is the primary executable or not. */
primary?: boolean;
/** Custom args to append to user-provided args within the generated shim. */
shimAfterArgs?: StringOrVec | null;
/** Custom args to prepend to user-provided args within the generated shim. */
Expand All @@ -289,9 +284,15 @@ export interface ExecutableConfig {

/** Output returned by the `locate_executables` function. */
export interface LocateExecutablesOutput {
/**
* Configures executable information to be used as proto bins/shims.
* The map key will be the name of the executable file.
*/
exes?: Record<string, ExecutableConfig>;
/**
* Relative directory path from the tool install directory in which
* pre-installed executables can be located.
* pre-installed executables can be located. This directory path
* will be used during `proto active`, but not for bins/shims.
*/
exesDir?: string | null;
/**
Expand Down
6 changes: 3 additions & 3 deletions registry/data/third-party.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
"name": "openfga",
"description": "OpenFGA is an open-source authorization solution that allows developers to build granular access control.",
"author": "crashdump",
"homepageUrl": "https://openfga.dev",
"homepageUrl": "https://openfga.dev/",
"repositoryUrl": "https://github.com/crashdump/proto-tools",
"bins": [
"openfga"
Expand Down Expand Up @@ -826,14 +826,14 @@
"sops"
]
},
{
{
"id": "staticcheck",
"locator": "https://raw.githubusercontent.com/crashdump/proto-tools/main/toml-plugins/staticcheck/plugin.toml",
"format": "toml",
"name": "staticcheck",
"description": "Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules.",
"author": "crashdump",
"homepageUrl": "https://staticcheck.dev",
"homepageUrl": "https://staticcheck.dev/",
"repositoryUrl": "https://github.com/crashdump/proto-tools",
"bins": [
"staticcheck"
Expand Down
4 changes: 3 additions & 1 deletion registry/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@
"description": "Format of the plugin.",
"type": "string",
"enum": [
"json",
"toml",
"wasm"
"wasm",
"yaml"
]
},
"PluginLocator": {
Expand Down

0 comments on commit 3b27de7

Please sign in to comment.