I have an issue with my yargs configuration:
const argv = require('yargs')
.boolean('reset', {
alias: 'rs'
})
.boolean('refreshConfig', {
alias: 'rc'
})
.option('harvest', {
alias: 'h'
})
.option('lang', {
alias: 'l',
default: 'fr'
})
.help().argv;
I executed the script as below:
$ node ./srcjobs/cli.js --refreshConfig --harvest=facebook
and I received this error:
Too many arguments provided. Expected max 1 but received 2.
Do you know why ?
Thank you for your help.
.boolean receive only 1 argument, from source code
boolean<K extends string>(key: K | ReadonlyArray<K>): Argv<T & { [key in K]: boolean | undefined }>;
Proper way
const argv = require('yargs')
.boolean('reset')
.alias('rs', 'reset')
.boolean('refreshConfig')
.alias('rc', 'refreshConfig')
.option('harvest', {
alias: 'h'
})
.option('lang', {
alias: 'l',
default: 'fr'
})
.help().argv;
Related
Given the following struct definition:
#[derive(Builder)]
pub struct Command {
executable: String,
#[builder(each = "arg")]
args: Vec<String>,
#[builder(each = "env")]
env: Vec<String>,
current_dir: Option<String>,
}
(where the #[builder(...)] attributes are inert attributes defined by my Builder derive macro implementation),
the Builder macro cannot "see" the #[builder(...)] field attributes. The following code
let name = &f.ident;
let attrs = &f.attrs;
println!("Attributes: {:?}: {}", name, attrs.len());
(where f is a syn::Field) gives
Attributes: Some(Ident { ident: "executable", span: #0 bytes(2830..2840) }): 0
Attributes: Some(Ident { ident: "args", span: #0 bytes(2854..2858) }): 0
Attributes: Some(Ident { ident: "env", span: #0 bytes(2877..2880) }): 0
Attributes: Some(Ident { ident: "current_dir", span: #0 bytes(2899..2910) }): 0
(Full code: https://github.com/pdkovacs/forked-proc-macro-workshop/blob/a471007968f974ea3c1c684cc47a77fbd20b91dc/builder/src/lib.rs)
Can anybody help me find out what I am missing here, please?
I think you might just be interpreting the terminal output incorrectly since when I cloned your fork and removed the test code that failed to compile this is the output I got for the test with the attributes:
test tests/07-repeated-field.rs ... ok
WARNINGS:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
warning: unused import: `builder_trait:: Builder`
--> tests/07-repeated-field.rs:32:5
|
32 | use builder_trait:: Builder;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: 1 warning emitted
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
STDOUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Attributes: Some(Ident { ident: "executable", span: #0 bytes(1471..1481) }): 0
Attributes: Some(Ident { ident: "args", span: #0 bytes(1524..1528) }): 1
Attributes: Some(Ident { ident: "env", span: #0 bytes(1576..1579) }): 1
Attributes: Some(Ident { ident: "current_dir", span: #0 bytes(1598..1609) }): 0
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
STDERR:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
warning: unused import: `builder_trait:: Builder`
--> /home/cassy/projects/forked-proc-macro-workshop/builder/tests/07-repeated-field.rs:32:5
|
32 | use builder_trait:: Builder;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
To be clear I completely commented out the body of main in 07-repeated-field.rs since it was failing to compile, and doing so allowed me to see this output.
I haven't used trybuild before but it seems like if a test fails to build then it doesn't give you the output from the proc macro invocation. Moreover it displays the STDOUT/STDERR of the test compilation process after it displays the test name, which likely was the source of the confusion.
i am trying to use Nipplejs in my Vue Project with quasar Components.
I installed nipplejs by npm install nipplejs --save.
I tried to integrate the nipple with the following code:
<template>
<div id="joystick_zone"></div>
</template>
<script lang= "ts">
// Imports
import Vue from "vue";
import nipplejs from 'nipplejs';
export default Vue.extend({
async mounted(): Promise<void> {
var options = {
zone: document.getElementById('joystick_zone') as HTMLElement,
mode: 'static',
color: `'blue'`,
}
var manager = nipplejs.create(options);
}
});
My first problem is that typescript doesnt accept 'static' as mode:
The definition says: mode?: 'dynamic' | 'semi' | 'static';
And i get the following error message:
Argument of type '{ zone: HTMLElement; mode: string; color: string; }' is not assignable to parameter of type 'JoystickManagerOptions'.
Types of property 'mode' are incompatible.
Type 'string' is not assignable to type '"dynamic" | "semi" | "static" | undefined'.
My second problem is that the joystick does not appear on the website.
If someone could help i would be very thankful.
If you would look into the definition of options variable you created. You would see it is of type { zone: HTMLElement; mode: string; color: string; }.
You must assign a type to the options variable.
var options: JoystickManagerOptions = {
zone: document.getElementById('joystick_zone') as HTMLElement,
mode: 'static',
color: 'blue',
};
Other option is to define the variable as const:
var options = {
zone: document.getElementById('joystick_zone') as HTMLElement,
mode: 'static',
color: 'blue',
} as const;
// Variable is now of type
type options = {
zone: HTMLElementHTMLElement;
mode: 'static';
color: 'blue';
}
I am working through the tutorial where it says how to create a contract.
Here is their code:
function createFirstPing() {
const request = {
commands: {
applicationId: 'PingPongApp',
workflowId: `Ping-${sender}`,
commandId: uuidv4(),
ledgerEffectiveTime: { seconds: 0, nanoseconds: 0 },
maximumRecordTime: { seconds: 5, nanoseconds: 0 },
party: sender,
list: [
{
create: {
templateId: PING,
arguments: {
fields: {
sender: { party: sender },
receiver: { party: receiver },
count: { int64: 0 }
}
}
}
}
]
}
};
client.commandClient.submitAndWait(request, (error, _) => {
if (error) throw error;
console.log(`Created Ping contract from ${sender} to ${receiver}.`);
});
}
I want to create a similar request for in my project that sends a field called 'datetime_added'. In my DAML code it is of type time. I cannot figure out the proper syntax for this request. For example:
arguments: {
fields: {
sender: { party: sender },
receiver: { party: receiver },
count: { int64: 0 },
datetime_added: { time: '2019 Feb 19 00 00 00' }
}
}
The format I am expressing the time is not what is causing the problem (although I acknowledge that it's also probably wrong). The error I'm seeing is the following:
Error: ! Validation error
▸ commands
▸ list
▸ 0
▸ create
▸ arguments
▸ fields
▸ datetime_added
✗ Unexpected key time found
at CommandClient.exports.SimpleReporter [as reporter] (/home/vantage/damlprojects/loaner_car/node_modules/#da/daml-ledger/lib/data/reporting/simple_reporter.js:36:12)
at Immediate.<anonymous> (/home/vantage/damlprojects/loaner_car/node_modules/#da/daml-ledger/lib/data/client/command_client.js:52:62)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
I don't understand, is time not a valid DAML data type?
Edit
I tried switching time to timestamp as follows
datetime_added: {timestamp: { seconds: 0, nanoseconds: 0 }}
causing the following error:
/home/......../damlprojects/car/node_modules/google-protobuf/google-protobuf.js:98
goog.string.splitLimit=function(a,b,c){a=a.split(b);for(var d=[];0<c&&a.length;)d.push(a.shift()),c--;a.length&&d.push(a.join(b));return d};goog.string.editDistance=function(a,b){var c=[],d=[];if(a==b)return 0;if(!a.length||!b.length)return Math.max(a.length,b.length);for(var e=0;e<b.length+1;e++)c[e]=e;for(e=0;e<a.length;e++){d[0]=e+1;for(var f=0;f<b.length;f++)d[f+1]=Math.min(d[f]+1,c[f+1]+1,c[f]+Number(a[e]!=b[f]));for(f=0;f<c.length;f++)c[f]=d[f]}return d[b.length]};goog.asserts={};goog.asserts.ENABLE_ASSERTS=goog.DEBUG;goog.asserts.AssertionError=function(a,b){b.unshift(a);goog.debug.Error.call(this,goog.string.subs.apply(null,b));b.shift();this.messagePattern=a};goog.inherits(goog.asserts.AssertionError,goog.debug.Error);goog.asserts.AssertionError.prototype.name="AssertionError";goog.asserts.DEFAULT_ERROR_HANDLER=function(a){throw a;};goog.asserts.errorHandler_=goog.asserts.DEFAULT_ERROR_HANDLER;
AssertionError: Assertion failed
at new goog.asserts.AssertionError (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:98:603)
at Object.goog.asserts.doAssertFailure_ (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:99:126)
at Object.goog.asserts.assert (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:99:385)
at jspb.BinaryWriter.writeSfixed64 (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:338:80)
at proto.com.digitalasset.ledger.api.v1.Value.serializeBinaryToWriter (/home/vantage/damlprojects/loaner_car/node_modules/#da/daml-ledger/lib/grpc/generated/com/digitalasset/ledger/api/v1/value_pb.js:289:12)
at jspb.BinaryWriter.writeMessage (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:341:342)
at proto.com.digitalasset.ledger.api.v1.RecordField.serializeBinaryToWriter (/home/vantage/damlprojects/loaner_car/node_modules/#da/daml-ledger/lib/grpc/generated/com/digitalasset/ledger/api/v1/value_pb.js:1024:12)
at jspb.BinaryWriter.writeRepeatedMessage (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:350:385)
at proto.com.digitalasset.ledger.api.v1.Record.serializeBinaryToWriter (/home/vantage/damlprojects/loaner_car/node_modules/#da/daml-ledger/lib/grpc/generated/com/digitalasset/ledger/api/v1/value_pb.js:822:12)
at jspb.BinaryWriter.writeMessage (/home/vantage/damlprojects/loaner_car/node_modules/google-protobuf/google-protobuf.js:341:342)
In short, I need to know what type to use in my Node.js client for a DAML value of type time and how to express it.
I would recommend using the reference documentation for the bindings (although, as of version 0.4.0, browsing through it to answer your question I noticed two mistakes). In the upper navigation bar of the page you can start from Classes > data.CommandClient and work your way down its only argument (SubmitAndWaitRequest) until, following the links to the different fields, you reach the documentation for the timestamp field, which, as the error suggests (despite the mistake in the documentation), should be a Timestamp, where seconds are expressed in epoch time (seconds since 1970).
Hence, to make the call you wanted this would be the shape of the object you ought to send:
arguments: {
fields: {
sender: { party: sender },
receiver: { party: receiver },
count: { int64: 0 }
datetime_added: { timestamp: { seconds: 0, nanoseconds: 0 } }
}
}
For your case in particular, I would probably make a small helper that uses the Date.parse function.
function parseTimestamp(string) {
return { seconds: Date.parse(string) / 1000, nanoseconds: 0 };
}
That you can then use to pass in the time you mentioned in the example you made:
arguments: {
fields: {
sender: { party: sender },
receiver: { party: receiver },
count: { int64: 0 }
datetime_added: { timestamp: parseTimestamp('2019-02-19') }
}
}
As a closing note, I'd like to add that the Node.js bindings ship with typing files that provide auto-completion and contextual help on compatible editors (like Visual Studio Code). Using those will probably help you. Since the bindings are written in TypeScript, the typings are guaranteed to be always up to date with the API. Note that for the time being, the auto-completion works for the Ledger API itself but won't give you help for arbitrary records that target your DAML model (the fields object in this case).
Here using node js ill send request but they give me en error ,add key to the config. I have a key but dont know how to add it?
My code is:
var GoogleMapsAPI = require('googlemaps');
var config = require('config');
var gmAPI = new GoogleMapsAPI();
var params = {
center: '444 W Main St Lock Haven PA',
zoom: 15,
size: '500x400',
maptype: 'roadmap',
markers: [
{
location: '300 W Main St Lock Haven, PA',
label : 'A',
color : 'green',
shadow : true
},
{
location: '444 W Main St Lock Haven, PA',
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
}
],
style: [
{
feature: 'road',
element: 'all',
rules: {
hue: '0x00ff00'
}
}
],
path: [
{
color: '0x0000ff',
weight: '5',
points: [
'41.139817,-77.454439',
'41.138621,-77.451596'
]
}
]
};
gmAPI.staticMap(params); // return static map URL
gmAPI.staticMap(params, function(err, binaryImage) {
// fetch asynchronously the binary image
});
and they give me an error:
WARNING: No configurations found in configuration directory:/home/okayg/webstorm_projects/Google_map_API/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
/home/okayg/webstorm_projects/Google_map_API/node_modules/googlemaps/lib/staticMap.js:28
throw error;
^
Error: The staticMap API requires a key. You can add it to the config.
at module.exports [as staticMap] (/home/okayg/webstorm_projects/Google_map_API/node_modules/googlemaps/lib/staticMap.js:40:36)
at Object.<anonymous>
So, how can i add key as they say "using config"?
Thank you.
You can find the answer in the documentation:
https://www.npmjs.com/package/googlemaps
It should be something like:
var publicConfig = {
key: '<YOUR-KEY>',
stagger_time: 1000, // for elevationPath
encode_polylines: false,
secure: true, // use https
proxy: 'http://127.0.0.1:9999' // optional, set a proxy for HTTP requests
};
var gmAPI = new GoogleMapsAPI(publicConfig);
Hope this helps!
How do you set the log level for node when starting it from the command line? I admit, i'm a node.js newbie, but looking for something like node myapp.js --loglevel warn
You can overwrite the console.log,console.debug,console.error,console.warn functions to allow logLevels.
Check out my snippet written in typescript:
export type LogLevel = "debug" | "log" | "warn" | "error" | "none";
let logLevels = ["debug", "log", "warn", "error", "none"];
let shouldLog = (level: LogLevel) => {
// #ts-ignore
return logLevels.indexOf(level) >= logLevels.indexOf(global.logLevel);
};
// #ts-ignore
global.logLevel = "debug";
let _console=console
global.console = {
...global.console,
log: (message?: any, ...optionalParams: any[]) => {
shouldLog("log")&&_console.log(message, ...optionalParams);
},
warn: (message?: any, ...optionalParams: any[]) => {
shouldLog("warn") && _console.warn(message, ...optionalParams);
},
error: (message?: any, ...optionalParams: any[]) => {
shouldLog("error") && _console.error(message, ...optionalParams);
},
debug: (message?: any, ...optionalParams: any[]) => {
shouldLog("debug") && _console.debug(message, ...optionalParams);
},
};
Then you can use the console functions as usual and set the logLevel with globals.logLevel="warn",...
Not possibly quite what you are after but you can enable debugging within node by setting a NODE_DEBUG environment variable first.
E.g. export NODE_DEBUG="net" && node myapp.js will give debugging for network related node operations.
https://github.com/joyent/node/blob/master/lib/net.js#L66