Visual Studio Community 2017 spaces in launch.json args field - json

I'm currently trying to set the debugging startup arguments for a CMake based project in Visual Studio Community 2017. Normally this would be done via the launch.vs.json file. However, the arguments that I need to pass contain spaces in them. For example, the below launch.vs.json file should pass the arguemnts FIRST ARGUMENT and SECOND ARGUMENT as the first and second argument. However, the program ends up getting 4 arguments: FIRST, ARGUMENT, SECOND, and ARGUMENT. I've tried various different encodings for spaces, but cannot get a space to be encoded properly in the resulting arguments. This is especially problematic as one of the arguments to my program is a path inside C:\Program Files. As such, the path is broken into 2 separate arguments, rather than one as it should be. How do I make Visual Studio allow spaces within an argument?
For reference, launching via the command line with this command works as expected:
argtest.exe "FIRST ARGUMENT" "SECOND ARGUMENT"
launch.vs.json
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "argtest.exe",
"name": "argtest.exe",
"args": ["FIRST ARGUMENT", "SECOND ARGUMENT"]
}
]
}
test.c
#include <stdio.h>
int main(int argc, char ** argv) {
int i;
for (i = 0; i < argc; i++)
printf("%d = %s\n", i, argv[i]);
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.8.8)
project (argtest)
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/ )
add_executable(argtest test.c)

You need to include the quotes in the args strings and escape them. For example:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "argtest.exe",
"name": "argtest.exe",
"args": ["\"FIRST ARGUMENT\"", "\"SECOND ARGUMENT\""]
}
]
}

It is easier doing this through Visual Studio itself. To run a program with command-line arguments follow these steps:
Open the project in Visual Studio
Click on the 'Debug' tab in the menu bar.
Click on the '[NAME OF PROJECT] Properties' menu item.
A window will popup and should automatically go into the Debug menu within that window. Under the 'Start options' section enter your command-line arguments with a space between each argument.
Hope this helps.

Related

nx:run-commands default args values

i have react library created inside nx mono repo using this version
nx: 15.6.3
i've added inside the packages/my-library command to run multiple commands
generate react component
generate react-stories
using these plugins #nrwl/react:component - #nrwl/react:component-story
this is the target
"generate-atom": {
"executor": "nx:run-commands",
"options": {
"commands": [
{
"command": "nx g #nrwl/react:component --project=core --style=#emotion/styled --export --directory=atoms/{args.group} --name={args.name}",
"forwardAllArgs": true,
"bgColor": "bgBlue"
},
{
"command": "nx g #nrwl/react:component-story --project=core --componentPath=atoms/{args.group || 'common'}/{args.name}/{args.name}.tsx",
"forwardAllArgs": true
}
],
"cwd": "packages/core",
"parallel": false
}
},
the components is been created inside when i call this target from nx
packages/core/src/atoms/undefined/button
this is the command i'm using
npx nx run core:generate-atom --args="--name=button"
any idea how can we default the value of group if was not passed?

Converting Packer 1.6 vsphere-iso configuration code from JSON to HCL2

With the release of Packer 1.6 came several depreciated fields in the vsphere-iso builder. From the looks of it, seems to be a format/type change because the fields actually still exists but just as properties it seems. An example of the changes are the following:
Working in Packer 1.5.6:
JSON
"disk_size": 123456,
"disk_thin_provisioned": true
"network": "VM Network",
"network_card": "vmxnet3"
Working in Packer 1.6.0:
JSON
"storage": [
{
"disk_size": 123456,
"disk_thin_provisioned": true
}
],
"network_adapters": [
{
"network": "VM Network",
"network_card": "vmxnet3"
}
]
The issue I have at the moment is I'm using Packer 1.6.0 and am trying to convert the above working JSON code to HCL2. I can't figure out the HCL2 syntax that supports the changes that were made in Packer 1.6.0.
I've tried the following:
network_adapters = {
network_card = "vmxnet3"
network = "VM Network"
}
Output:
An argument named "network_adapter" is not expected here.
network_adapters = (
network_card = "vmxnet3"
network = "VM Network"
)
Output:
Error: Unbalanced parentheses
on .\Packer\ConfigFileName.pkr.hcl line 19, in source "vsphere-iso"
"Test": 18: storage = ( 19: disk_thin_provisioned = true
Expected a closing parenthesis to terminate the expression.
network_adapters = [
network_card = "vmxnet3",
network = "VM Network"
]
Output:
Error: Missing item separator
on .\Packer\ConfigFileName.pkr.hcl line 19, in source "vsphere-iso"
"Test": 18: storage = [ 19: disk_thin_provisioned =
true,
Expected a comma to mark the beginning of the next item.
I've also tried several other permutations of different collection syntax together with no luck so far. Any suggestions or tips would greatly be appreciated
The correct syntax is the following:
network_adapters {
network_card = "vmxnet3",
network = "VM Network"
}
Note that it's not using an assignment operator = between network_adapters and {
Credit goes to SwampDragons over on the Packer forums for pointing this out.
If you're interested in knowing why: There was a change to how maps are treated in HCL2 back in May 2020 with the release of Packer 1.5.6
core/hcl2: Maps are now treated as settable arguments as opposed to blocks. For example tags = {} instead of tags {} [GH-9035]
Reference: https://github.com/hashicorp/packer/blob/master/CHANGELOG.md#156-may-1-2020

How to define config file variables?

I have a configuration file with:
{path, "/mnt/test/"}.
{name, "Joe"}.
The path and the name could be changed by a user. As I know, there is a way to save those variables in a module by usage of file:consult/1 in
-define(VARIABLE, <parsing of the config file>).
Are there any better ways to read a config file when the module begins to work without making a parsing function in -define? (As I know, according to Erlang developers, it's not the best way to make a complicated functions in -define)
If you need to store config only when you start the application - you may use application config file which is defined in 'rebar.config'
{profiles, [
{local,
[{relx, [
{dev_mode, false},
{include_erts, true},
{include_src, false},
{vm_args, "config/local/vm.args"}]
{sys_config, "config/local/yourapplication.config"}]
}]
}
]}.
more info about this here: rebar3 configuration
next step to create yourapplication.config - store it in your application folder /app/config/local/yourapplication.config
this configuration should have structure like this example
[
{
yourapplicationname, [
{path, "/mnt/test/"},
{name, "Joe"}
]
}
].
so when your application is started
you can get the whole config data with
{ok, "/mnt/test/"} = application:get_env(yourapplicationname, path)
{ok, "Joe"} = application:get_env(yourapplicationname, name)
and now you may -define this variables like:
-define(VARIABLE,
case application:get_env(yourapplicationname, path) of
{ok, Data} -> Data
_ -> undefined
end
).

How can I append to a list inside a JSON file in Clojure?

I need to write an output in a JSON file which grows longer over time. What I have:
{
"something": {
"foo" : "bar"
}
}
And I use (spit "./my_file" my-text :append true).
With append, I include new entries, and it looks like this:
{
"something": {
"foo": "bar"
}
},
{
"something": {
"foo": "bar"
}
},
}
My problem is that I need something like this:
[
{
"something": {
"foo": "bar"
}
},
{
"something": {
"foo": "bar"
}
}
]
But I really do not know how to include new data within the [ ]
If you want to perform updates in-place -- meaning you care more about performance than safety -- this can be accomplished using java.io.RandomAccessFile:
(import '[java.io RandomAccessFile])
(defn append-to-json-list-in-file [file-name new-json-text]
(let [raf (RandomAccessFile. file-name "rw")
lock (.lock (.getChannel raf)) ;; avoid concurrent invocation across processes
current-length (.length raf)]
(if (= current-length 0)
(do
(.writeBytes raf "[\n") ;; On the first write, prepend a "["
(.writeBytes raf new-json-text) ;; ...before the data...
(.writeBytes raf "\n]\n")) ;; ...and a final "\n]\n"
(do
(.seek raf (- current-length 3)) ;; move to before the last "\n]\n"
(.writeBytes raf ",\n") ;; put a comma where that "\n" used to be
(.writeBytes raf new-json-text) ;; ...then the new data...
(.writeBytes raf "\n]\n"))) ;; ...then a new "\n]\n"
(.close lock)
(.close raf)))
As an example of usage -- if no preexisting out.txt exists, then the result of the following three calls:
(append-to-json-list-in-file "out.txt" "{\"hello\": \"birds\"}")
(append-to-json-list-in-file "out.txt" "{\"hello\": \"trees\"}")
(append-to-json-list-in-file "out.txt" "{\"goodbye\": \"world\"}")
...will be a file containing:
[
{"hello": "birds"},
{"hello": "trees"},
{"goodbye": "world"}
]
Note that the locking prevents multiple processes from calling this code at once with the same output file. It doesn't provide safety from multiple threads in the same process doing concurrent invocations -- if you want that, I'd suggest using an Agent or other inherently-single-threaded construct.
There's also some danger that this could corrupt a file that has been edited by other software -- if a file ends with "\n]\n\n\n" instead of "\n]\n", for example, then seeking to three bytes before the current length would put us in the wrong place, and we'd generate malformed output.
If instead you care more about ensuring that output is complete and not corrupt, the relevant techniques are not JSON-specific (and call for rewriting the entire output file, rather than incrementally updating it); see Atomic file replacement in Clojure.

How to keep appium capabilities in json file and call in code

Following is my appium capability set to run a test
cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PLATFORM, "Android");
cap.setCapability(CapabilityType.VERSION, "5.1.0");
cap.setCapability("deviceName", "mygeny510");
cap.setCapability("appPackage", "com.android.dialer");
cap.setCapability("appActivity", "com.android.dialer.DialtactsActivity");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
I want to keep the capabilities in a apm.json file
[
{
"platformName": "android",
"appPackage":"com.android.dialer",
"appActivity": "com.android.dialer.DialtactsActivity",
"deviceName": "mygeny510"
}
]
Now can anyone help to call the apm.json into the code instead writing each capabilities by using cap.setcapability(,)
You can place all the desired capabilities on to a seperate file and load the file in an other file for referencing it.
For eg,
I have the desired capabilities in env.rb
def abc
{
caps:
{
platformName: "iOS",
deviceName: "",
udid: "",
app: (File.join(File.dirname(__FILE__), "")),
bundleId: "",
automationName: "XCUITest",
xcodeOrgId: "",
xcodeSigningId: "",
platformVersion: "9.3.2",
noReset: "true",
fullReset: "false",
showIOSLog: "true"
}
}
end
Now you can go to the file where you want to launch this desired capabilities. For this, you would need to load the .json file into this file. I have used require_relative to load the file in order to call the method. Once you do that, you can start the session with
def AnyName
Appium::Driver.new(abc) #Pass capabilities for appium inside the driver
Appium.promote_appium_methods Object #Makes all appium_lib methods accessible from steps
$driver.start_driver #Starts appium driver before the tests begin
end
Hope this helps!