Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass a parameter to a F# FAKE build script?

Tags:

I'm just getting started with FAKE. I really like the idea. In the tutorials the set the build and deploy directories.

// Directories let buildDir  = "./build/" let testDir   = "./test/" let deployDir = "./deploy/" 

and then later reference those which is fine, but is it possible to pass that as a parameter? Maybe to as Task where I can use it later?

like image 708
awright18 Avatar asked Oct 08 '14 22:10

awright18


People also ask

How can parameters be passed to a function?

Arguments are Passed by Value The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.

Can you pass a variable to a function?

In JavaScript, you cannot pass parameters by reference; that is, if you pass a variable to a function, its value is copied and handed to the function (pass by value). Therefore, the function can't change the variable. If you need to do so, you must wrap the value of the variable (e.g., in an array).

How do you pass a parameter to a function in Python?

Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

Can we pass a function as a parameter in for function?

We cannot pass the function as an argument to another function. But we can pass the reference of a function as a parameter by using a function pointer. This process is known as call by reference as the function parameter is passed as a pointer that holds the address of arguments.


2 Answers

Something like this should work.

From the command-line:

"..\packages\Fake.3.7.5\tools\Fake.exe" "build.fsx" dir=my/custom/dir/ 

In the build.fsx script:

let buildDir = getBuildParamOrDefault "dir" "./build/" 

That will look for the dir parameter being passed in, and use it if it's assigned, otherwise it will default to ./build/

like image 178
danmiser Avatar answered Oct 14 '22 14:10

danmiser


Non of the above fully worked for me. Below an adjusted solution.
The console command needs to be run with the -e flag:

"..\fake.exe" "build.fsx" -e dir=sample/directory 

The build script is using Environment.environVarOrDefault "dir" "default\directory":

let buildDir = Environment.environVarOrDefault "dir" "default\directory" 

Environment.environVar can also be used if no alternative is provided.

Finally the build script has to run with Target.runOrDefaultWithArguments. It will fail if it's executed with Target.runOrDefault:

// start build Target.runOrDefaultWithArguments "DefaultBuildTarget" 
like image 32
PiotrWolkowski Avatar answered Oct 14 '22 12:10

PiotrWolkowski