Scripting
Scripts and tasks are written in Kotlin, an awesome programming language for manipulating nullable objects, callbacks, and types.
You can learn it here: http://try.kotlinlang.org/koans
They use Java-IPFS-API for interacting with IPFS
You can compile them easily with Kotlin-Compiler-GUI
Here is a video: IPFS-Manager #1 : Compiling & Running a script
Scripts
A script is a simple class that is enabled when the manager is connected
import fr.rhaz.ipfs.KScript
import fr.rhaz.ipfs.append
public class ExampleScript: KScript("script"){
override fun onEnabled() = log.append("Hello world!")
}
This script will write “Hello world!” to the console
Tasks
A task is a script that can be run when you type its name in the console
You can use tasks to automate actions like adding files, retrieve domains, publish IPNS, …
import fr.rhaz.ipfs.Task
import fr.rhaz.ipfs.append
public class ExampleTask: Task("example"){
override fun onEnabled() = log.append("ExampleTask enabled!")
override fun onCall(line: String){
val version = ipfs.version() ?: return
// Request the version. If there is an error, do not continue
log.append(version)
// Write the version
val args = line.split(" ")
// Split the line in multiple arguments
if(args.size > 1) log.append(args[1])
// If there is at least two arguments (the command + the first argument)
// then write the first argument
}
}
This task writes “ExampleTask enabled!” in the console when the manager is connected
When you type “example” (its name), it writes the IPFS version
When you type “example anything” (“anything” can be anything), it will write the IPFS version followed by what you wrote