So I know how to create variables and store values from command line.
But normally, I would type my command this way: make run VAR="abc", and VAR will be assigned the new value "abc"
However, if I want to do something like this VAR="abc" make run, how can I change my make file? Right now, if I run this, VAR still has the initial value when it was created in the make file.
This is my make file:
VAR = ""
.PHONY : build run
build : program.c
gcc -o prog -g program.c
run : build
./prog $(VAR)
When you write VAR = "", you're overwriting any value VAR might have had (e.g. from the environment, or the command line). You can use a conditional assignment instead, which looks like this:
VAR ?= ""
This sets VAR only if it wasn't set already. It's equivalent to e.g.
ifeq ($(origin VAR), undefined)
VAR = ""
endif
VAR = ${VAR}
if i remember right
Related
I have the following code, which reads what task name I passed to gulp: release or test and decides what task group to load from the files based on that.
var argv = require('yargs').argv;
var group = argv._[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);
Isn't there a better way to get the commanded tasks from gulp itself instead of using yargs?
I found a great tutorial about tools for CLI. According to it I should use commander, so I do so. It is much better than yargs. Another possible solution to use process.argv[2] in this case, but it is much better to use a parser in long term.
var program = require("commander");
program.parse(process.argv);
var group = program.args[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);
I am using gulp and gulp-shell packages for a php Laravel application, I just need to know if this is possible to pass argument from cmd to gulpfile.js ? this is my file:
gulp.task('default', shell.task([
'echo user',
]));
Question:
Is it possible to pass an argument from command-line when running gulp and then inside the gulpfile print it out instead of user?
var command_line_args = require('yargs').argv
Not sure if this is of any use to you or others but I did this manually by passing the arguments explicitly through a custom function. It's not super elegant but it gets the job done.
var appendWithCommandLineArguments = function(cmd, arguments) {
var to_append = _.chain(command_line_args)
.pick(arguments)
.reduce(function(string, val, prop){
return string+"--"+prop+"="+val+" ";
}, " ")
.value();
return cmd + to_append
}
gulp.task('taskmailer', shell.task([
appendWithCommandLineArguments('node automate/build/mail/taskMailer.js', ["email", "template"])
]))
I am working with mongo client. Sometimes the output of some commands I execute involve an enormous output, which mongo prints on screen. How can I avoid this?
There is a way to suppress output.
Using "var x = ...;" allows to hide output of expressions.
But there are other commands that harder to suppress like
Array.prototype.distinct = function() {
return [];
}
This produces printing of new defined function.
To suppress it you will need to write it in this way:
var suppressOutput = (
Array.prototype.distinct = function() {
return [];
}
);
Per the comment by #WiredPrairie, this solution worked for me:
Just set the return value to a local variable: var x=db.so.find(); and inspect it as needed.
I want to execute a command and parse the output from the shell. I am using JScript inside TestComplete. I already found out that I can run commands using WScript.shell. But I do not know how to parse the output in my JScript. Any hints?
var shell = new ActiveXObject("WScript.shell");
if (shell)
{
shell.run("myCommandIWantToParseOutputfrom.sh");
}
Take a look at the Exec method instead of Run.
var wsh = new ActiveXObject("WScript.Shell");
var cmd = wsh.Exec("cmd /c dir C:\ /on");
while (cmd.Status === 0) {
WScript.Sleep(100);
}
var output = cmd.StdOut.ReadAll();
WScript.Echo(output);
I am trying to make a command line util to let me register updates to my TFS SSRS reports.
I am using rs.exe. It has the -v option where you can pass in a parameter. Is there a way to pass in an array (or some kind of collection).
I would like to pass in an array of Data Source Names.
I ran into the same problem and came up with this solution:
Powershell
$RssScriptPath = "C:\myRssScript.rss"
$TargetSsrsServer = "http:\\localhost\reportserver"
$MyStringArray = "val1", "val2", "val3"
& rs.exe -i $RssScriptPath -s $TargetSsrsServer -v _myStringArray=$MyStringArray
Rss script (VB)
Dim _phrase As String() = _myStringArray.Split(",")
Dim _values As String() = _phrase(0).Split(" ")
For index As Integer = 0 To _values .GetUpperBound(0)
PublishReport(_values(index))
Next
I only tried with a strings, but you may be able to use the same strategy to pass other types.