defmodule MyspaceIPFS.Commands do
@moduledoc """
MyspaceIPFS.Commands is where the commands commands of the IPFS API reside.
"""
import MyspaceIPFS.Api
import MyspaceIPFS.Utils
alias MyspaceIPFS.CommandsCommand
@typedoc """
A struct that represents a command object.
"""
@type command :: %MyspaceIPFS.CommandsCommand{
name: binary,
options: list,
subcommands: list
}
@doc """
List all available commands.
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-commands
"""
@spec commands() :: {:ok, any} | MyspaceIPFS.Api.error_response()
def commands() do
post_query("/commands")
|> CommandsCommand.new()
|> okify()
end
@doc """
Generate command autocompletion script.
NB! These completions aren't actually in the API, but are generated by the
client. This requires shell access to the client machine. If you want shell
completions, you should install the IPFS CLI and use its completions.
## Parameters
https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-commands-completion
`shell` - The shell to generate the autocompletion script for. Currently
`bash` and `fish` are supported.
"""
@spec completion(binary) :: {:ok, any} | MyspaceIPFS.Api.error_response()
def completion(shell) do
System.cmd("ipfs", ["commands", "completion", shell])
|> elem(0)
end
end