cbrain icon indicating copy to clipboard operation
cbrain copied to clipboard

CBRAIN CLI

Open bryancaron opened this issue 8 months ago • 0 comments

See GSOC description details as reference, copied below for future iterations and discussion.

  1. The CLI project should be developed in a separate GitHub repo. Do not make pull requests on the main CBRAIN project repo.

  2. the CLI project’s codebase should contain the minimal set of Python files to implement its core functionality. Do not include external libraries imported by your project, or files installed as part of a virtual environment.

Implementation

Single command ‘cbrain’ that runs in a Unix (Linux/Mac) terminal
The command is a python script that depends on CBRAIN API
libraries to perform its functions
The command has a standard argument structure:
    options starts with ‘-’, e.g. -j or --json
    other arguments are subcommands and their parameters
Session is maintained in a credentials.json file; advanced
features would be to be able to maintain several distinct
sessions and switch between them?

Examples

These are ‘vision’ examples, not to be taken as the literal product that this project expects. The developer is free to make adjustments and make things more convenient/pretty at any levels.

The lines starting with '> ’ represent the terminal’s prompt and show the ‘cbrain’ command with sample options and argument. Lines the follow show sample outputs. If these lines are in parenthesis, it means a description of the output is shown instead.

> cbrain
(shows the basic usage statement for the command)

> cbrain login
Enter CBRAIN server URL prefix: http://localhost:3000
Enter CBRAIN username: jdoe
Enter CBRAIN password: *********
Connection successful, API token saved in $HOME/.config/cbrain/credentials.json

> cbrain whoami
Current user: jdoe (John Doe) on server http://localhost:3000

> cbrain -v whoami
DEBUG: Found credentials $HOME/.config/cbrain/credentials.json
DEBUG: User in credentials: jdoe on server http://localhost:3000
DEBUG: Token found: a3****b2
DEBUG: Verifying token...
DEBUG: GET /session
DEBUG: Got JSON reply {"user_id":23,"cbrain_api_token":"0123456789abcdeffedcba9876543210"}
DEBUG: GET /users/23
DEBUG: Got JSON reply {"id":23,"login":"jdoe","full_name":"John Doe","email":...}
Current user: jdoe (John Doe) on server http://localhost:3000

> cbrain list projects
ID Type        Project Name
-- ----------- ----------------
34 UserProject jdoe
55 WorkProject my_research

> cbrain --json list projects
[
  { "id": 34, "type": "UserProject", "name": "jdoe" },
  { "id": 55, "type": "WorkProject", "name": "myresearch" }
]

> cbrain switch project 34
Current project is now "jdoe" ID=34

> cbrain show project
Current project is "jdoe" ID=34

> cbrain switch project ALL
No current project selected, everything is unfiltered.

> cbrain list files
ID   Type        File Name
---- ----------- -----------------------
2616 TextFile    license.txt
9221 CivetOutput sub-1234_feb24-beluga-1

> cbrain --json list files
(same list but in JSON)

> cbrain list tools
> cbrain list tool_configs
> cbrain list tasks
> cbrain list users
(note: would only list one user unless the user is admin)
> cbrain list data_providers
> cbrain list remote_resources
> cbrain list background_activitites

> cbrain list files where group_id=55 data_provider_id=27
(only shows files based on filters, which are just sent back to the server
as query parameters; cbrain client can validate the keys base on know
allowed filters)

> cbrain list tasks where bourreau_id=45

> cbrain upload 27 TextFile chapter1.txt < chapter1.txt
(27 is the ID of a data provider, the other two args are the type and name; the
content of the file is fed in the unix way from standard input)

> cbrain create task Civet < task_structure.json

> cbrain copy file 2616 27
Background activity ID: 453
(Arguments are file ID, destination data provider ID)

> cbrain move file 2617 27
Background activity ID: 454
(Arguments are file ID, destination data provider ID)

> cbrain --json show background_activity 453
{"id"=>453, "user_id"=>34, "type"=>"BackgroundActivity::CopyFile",
 "status"=>"Completed", "items"=>[2616], ... }

> cbrain show file 2616
id: 2616
type: TextFile
name: robot.txt
data_provider: 27
size: 4533
num_files: 1
user_id: 34
group_id: 55

> cbrain show task 12345
> cbrain show tool 13
> cbrain show tool_config 422
> cbrain show data_provider 27
> cbrain show remote_resource 45
(etc etc)

> cbrain logout

The tool should accept 'ls' and 'list', 'mv' and 'move', and 'show' and 'info', as equivalent, for example.

bryancaron avatar Apr 24 '25 13:04 bryancaron