Skip to content

Commit fd32c75

Browse files
committed
update logic and tests
1 parent e49ff3d commit fd32c75

File tree

10 files changed

+301
-142
lines changed

10 files changed

+301
-142
lines changed

desktop/src-tauri/src/types/generated/workspace.rs

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,64 @@ impl ExecutableFilter {
122122
Default::default()
123123
}
124124
}
125+
#[doc = "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and its mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n"]
126+
#[doc = r""]
127+
#[doc = r" <details><summary>JSON schema</summary>"]
128+
#[doc = r""]
129+
#[doc = r" ```json"]
130+
#[doc = "{"]
131+
#[doc = " \"description\": \"A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\\nSetting this will override all of the default flow command aliases. The verbs and its mapped aliases must be valid flow verbs.\\n\\nIf set to an empty object, verb aliases will be disabled.\\n\","]
132+
#[doc = " \"type\": \"object\","]
133+
#[doc = " \"additionalProperties\": {"]
134+
#[doc = " \"type\": \"array\","]
135+
#[doc = " \"items\": {"]
136+
#[doc = " \"type\": \"string\""]
137+
#[doc = " }"]
138+
#[doc = " }"]
139+
#[doc = "}"]
140+
#[doc = r" ```"]
141+
#[doc = r" </details>"]
142+
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
143+
#[serde(transparent)]
144+
pub struct VerbAliases(
145+
pub ::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>,
146+
);
147+
impl ::std::ops::Deref for VerbAliases {
148+
type Target =
149+
::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>;
150+
fn deref(
151+
&self,
152+
) -> &::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>
153+
{
154+
&self.0
155+
}
156+
}
157+
impl ::std::convert::From<VerbAliases>
158+
for ::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>
159+
{
160+
fn from(value: VerbAliases) -> Self {
161+
value.0
162+
}
163+
}
164+
impl ::std::convert::From<&VerbAliases> for VerbAliases {
165+
fn from(value: &VerbAliases) -> Self {
166+
value.clone()
167+
}
168+
}
169+
impl
170+
::std::convert::From<
171+
::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>,
172+
> for VerbAliases
173+
{
174+
fn from(
175+
value: ::std::collections::HashMap<
176+
::std::string::String,
177+
::std::vec::Vec<::std::string::String>,
178+
>,
179+
) -> Self {
180+
Self(value)
181+
}
182+
}
125183
#[doc = "Configuration for a workspace in the Flow CLI.\nThis configuration is used to define the settings for a workspace.\nEvery workspace has a workspace config file named `flow.yaml` in the root of the workspace directory.\n"]
126184
#[doc = r""]
127185
#[doc = r" <details><summary>JSON schema</summary>"]
@@ -156,14 +214,7 @@ impl ExecutableFilter {
156214
#[doc = " \"$ref\": \"#/definitions/CommonTags\""]
157215
#[doc = " },"]
158216
#[doc = " \"verbAliases\": {"]
159-
#[doc = " \"description\": \"A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\\n\\nIf set to an empty object, verb aliases will be disabled.\\n\","]
160-
#[doc = " \"type\": \"object\","]
161-
#[doc = " \"additionalProperties\": {"]
162-
#[doc = " \"type\": \"array\","]
163-
#[doc = " \"items\": {"]
164-
#[doc = " \"type\": \"string\""]
165-
#[doc = " }"]
166-
#[doc = " }"]
217+
#[doc = " \"$ref\": \"#/definitions/VerbAliases\""]
167218
#[doc = " }"]
168219
#[doc = " }"]
169220
#[doc = "}"]
@@ -184,14 +235,12 @@ pub struct Workspace {
184235
pub executables: ::std::option::Option<ExecutableFilter>,
185236
#[serde(default = "defaults::workspace_tags")]
186237
pub tags: CommonTags,
187-
#[doc = "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n"]
188238
#[serde(
189239
rename = "verbAliases",
190240
default,
191-
skip_serializing_if = ":: std :: collections :: HashMap::is_empty"
241+
skip_serializing_if = "::std::option::Option::is_none"
192242
)]
193-
pub verb_aliases:
194-
::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>,
243+
pub verb_aliases: ::std::option::Option<VerbAliases>,
195244
}
196245
impl ::std::convert::From<&Workspace> for Workspace {
197246
fn from(value: &Workspace) -> Self {
@@ -283,13 +332,8 @@ pub mod builder {
283332
::std::string::String,
284333
>,
285334
tags: ::std::result::Result<super::CommonTags, ::std::string::String>,
286-
verb_aliases: ::std::result::Result<
287-
::std::collections::HashMap<
288-
::std::string::String,
289-
::std::vec::Vec<::std::string::String>,
290-
>,
291-
::std::string::String,
292-
>,
335+
verb_aliases:
336+
::std::result::Result<::std::option::Option<super::VerbAliases>, ::std::string::String>,
293337
}
294338
impl ::std::default::Default for Workspace {
295339
fn default() -> Self {
@@ -359,12 +403,7 @@ pub mod builder {
359403
}
360404
pub fn verb_aliases<T>(mut self, value: T) -> Self
361405
where
362-
T: ::std::convert::TryInto<
363-
::std::collections::HashMap<
364-
::std::string::String,
365-
::std::vec::Vec<::std::string::String>,
366-
>,
367-
>,
406+
T: ::std::convert::TryInto<::std::option::Option<super::VerbAliases>>,
368407
T::Error: ::std::fmt::Display,
369408
{
370409
self.verb_aliases = value

desktop/src/types/generated/workspace.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,7 @@ export interface Workspace {
3131
displayName?: string;
3232
executables?: ExecutableFilter;
3333
tags?: CommonTags;
34-
/**
35-
* A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.
36-
* Setting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.
37-
*
38-
* If set to an empty object, verb aliases will be disabled.
39-
*
40-
*/
41-
verbAliases?: {
42-
[k: string]: string[];
43-
};
34+
verbAliases?: VerbAliases;
4435
[k: string]: unknown;
4536
}
4637
export interface ExecutableFilter {
@@ -54,3 +45,13 @@ export interface ExecutableFilter {
5445
included?: string[];
5546
[k: string]: unknown;
5647
}
48+
/**
49+
* A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.
50+
* Setting this will override all of the default flow command aliases. The verbs and its mapped aliases must be valid flow verbs.
51+
*
52+
* If set to an empty object, verb aliases will be disabled.
53+
*
54+
*/
55+
export interface VerbAliases {
56+
[k: string]: string[];
57+
}

docs/schemas/workspace_schema.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
}
3333
}
3434
}
35+
},
36+
"VerbAliases": {
37+
"description": "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and its mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n",
38+
"type": "object",
39+
"additionalProperties": {
40+
"type": "array",
41+
"items": {
42+
"type": "string"
43+
}
44+
}
3545
}
3646
},
3747
"properties": {
@@ -58,14 +68,7 @@
5868
"default": []
5969
},
6070
"verbAliases": {
61-
"description": "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n",
62-
"type": "object",
63-
"additionalProperties": {
64-
"type": "array",
65-
"items": {
66-
"type": "string"
67-
}
68-
}
71+
"$ref": "#/definitions/VerbAliases"
6972
}
7073
}
7174
}

docs/types/workspace.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Every workspace has a workspace config file named `flow.yaml` in the root of the
1919
| `displayName` | The display name of the workspace. This is used in the interactive UI. | `string` | | |
2020
| `executables` | | [ExecutableFilter](#ExecutableFilter) | <no value> | |
2121
| `tags` | | [CommonTags](#CommonTags) | [] | |
22-
| `verbAliases` | A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace. Setting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs. If set to an empty object, verb aliases will be disabled. | `map` (`string` -> `array` (`string`)) | <no value> | |
22+
| `verbAliases` | | [VerbAliases](#VerbAliases) | <no value> | |
2323

2424

2525
## Definitions
@@ -50,4 +50,17 @@ Tags can be used with list commands to filter returned data.
5050
| `excluded` | A list of directories to exclude from the executable search. | `array` (`string`) | [] | |
5151
| `included` | A list of directories to include in the executable search. | `array` (`string`) | [] | |
5252

53+
### VerbAliases
54+
55+
A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.
56+
Setting this will override all of the default flow command aliases. The verbs and its mapped aliases must be valid flow verbs.
57+
58+
If set to an empty object, verb aliases will be disabled.
59+
60+
61+
**Type:** `map` (`string` -> `array` (`string`))
62+
63+
64+
65+
5366

internal/cache/executables_cache.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,23 @@ func (c *ExecutableCacheImpl) GetExecutableByRef(logger io.Logger, ref executabl
130130
return exec, nil
131131
}
132132

133+
var primaryRef executable.Ref
133134
cfgPath, found := c.Data.ExecutableMap[ref]
135+
//nolint:nestif
134136
if !found {
135-
if primaryRef, aliasFound := c.Data.AliasMap[ref]; aliasFound {
137+
if aliasedPrimaryRef, aliasFound := c.Data.AliasMap[ref]; aliasFound {
138+
primaryRef = aliasedPrimaryRef
136139
cfgPath, found = c.Data.ExecutableMap[primaryRef]
137140
if !found {
138141
return nil, NewExecutableNotFoundError(ref.String())
139142
}
140143
} else {
141144
return nil, NewExecutableNotFoundError(ref.String())
142145
}
146+
} else {
147+
primaryRef = ref
143148
}
149+
144150
cfg, err := filesystem.LoadFlowFile(cfgPath)
145151
if err != nil {
146152
return nil, errors.Wrap(err, "unable to load executable config")
@@ -165,7 +171,7 @@ func (c *ExecutableCacheImpl) GetExecutableByRef(logger io.Logger, ref executabl
165171
cfg.Executables = append(cfg.Executables, generated...)
166172

167173
execs := cfg.Executables
168-
exec, err := execs.FindByVerbAndID(ref.Verb(), ref.ID())
174+
exec, err := execs.FindByVerbAndID(primaryRef.Verb(), primaryRef.ID())
169175
if err != nil {
170176
return nil, err
171177
} else if exec == nil {
@@ -234,19 +240,26 @@ func (c *ExecutableCacheImpl) initExecutableCacheData(logger io.Logger) error {
234240

235241
func enumerateExecutableAliasRefs(
236242
exec *executable.Executable,
237-
override workspace.WorkspaceVerbAliases,
243+
override *workspace.WorkspaceVerbAliases,
238244
) executable.RefList {
239245
refs := make(executable.RefList, 0)
240246

241-
if override == nil {
247+
switch {
248+
case override == nil:
249+
// use default aliases
242250
for _, verb := range executable.RelatedVerbs(exec.Verb) {
243251
refs = append(refs, executable.NewRef(exec.ID(), verb))
244252
for _, id := range exec.AliasesIDs() {
245253
refs = append(refs, executable.NewRef(id, verb))
246254
}
247255
}
248-
} else {
249-
if verbs, found := override[exec.Verb.String()]; found {
256+
case len(*override) == 0:
257+
// disable all aliases if override is set but empty
258+
return refs
259+
default:
260+
// use overrides if provided
261+
o := *override
262+
if verbs, found := o[exec.Verb.String()]; found {
250263
for _, v := range verbs {
251264
vv := executable.Verb(v)
252265
if err := vv.Validate(); err != nil {

0 commit comments

Comments
 (0)