Skip to content

Commit

Permalink
Little more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 20, 2024
1 parent 30785dc commit 00804cf
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/api/autogen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class RustType {
toString() {
return this.rusty;
}

maybeVia() {
return this.convertVia ? `, via = ${this.convertVia}` : '';
}
}

function rusty(rusty: string, convertVia?: string) {
Expand Down Expand Up @@ -354,36 +358,38 @@ class DeviceMethod {
} as const
)[this.method];

let maybeVia = this.returnType.convertVia
? `, via = ${this.returnType.convertVia}`
: '';
let defaultImpl = 'Err(ASCOMError::NOT_IMPLEMENTED)';
if (this.name.startsWith('can_')) {
defaultImpl = 'Ok(false)';
} else if (this.inBaseDevice) {
switch (this.name) {
case 'name':
defaultImpl = 'Ok(self.static_name().to_owned())';
break;
case 'interface_version':
defaultImpl = 'Ok(3_i32)';
break;
case 'supported_actions':
defaultImpl = 'Ok(vec![])';
break;
}
}

return `
${stringifyDoc(this.doc)}
#[http("${this.path}", method = ${transformedMethod}${maybeVia})]
#[http("${
this.path
}", method = ${transformedMethod}${this.returnType.maybeVia()})]
async fn ${this.name}(
&self,
${this.resolvedArgs.toString(
arg =>
`
#[http("${arg.originalName}"${
arg.type.convertVia ? `, via = ${arg.type.convertVia}` : ''
})]
${arg.name}: ${arg.type},
`
arg => `
#[http("${arg.originalName}"${arg.type.maybeVia()})]
${arg.name}: ${arg.type},
`
)}
) -> ASCOMResult${this.returnType.ifNotVoid(type => `<${type}>`)} {
${
this.name.startsWith('can_')
? 'Ok(false)'
: this.inBaseDevice && this.name === 'name'
? 'Ok(self.static_name().to_owned())'
: this.inBaseDevice && this.name === 'interface_version'
? 'Ok(3_i32)'
: this.inBaseDevice && this.name === 'supported_actions'
? 'Ok(vec![])'
: 'Err(ASCOMError::NOT_IMPLEMENTED)'
}
${defaultImpl}
}
`;
}
Expand Down

0 comments on commit 00804cf

Please sign in to comment.