open-simulation-platform / cosim-cli

Command-line interface for libcosim
https://open-simulation-platform.github.io/cosim
Mozilla Public License 2.0
10 stars 4 forks source link

New subcommand: inspect #2

Closed kyllingstad closed 5 years ago

kyllingstad commented 5 years ago

This builds on the work in PR #1 and adds the first "non-builtin" subcommand: inspect. It works pretty much as specified in Confluence.

~I've targeted this on the PR #1 branch so that all you see is the stuff I've added. I'll retarget it on master once #1 is merged.~

Here is some example output:

> cse help inspect
NAME
  cse inspect - Shows information about a model

SYNOPSIS
  cse inspect <uri_or_path> [options...]

DESCRIPTION
  This command shows information about a model, such as its name,
  description, author, version, and so on.  It also lists information
  about the model's variables, like their names, types, causalities,
  variabilities, etc.

  The model can be specified with a URI, or, if it's a local FMU, by
  its path.  Using a path is equivalent to using a `file` URI.

PARAMETERS
  uri_or_path           A model URI or FMU path.

OPTIONS
  --no-vars             Do not print information about variables.
  --help                Display a help message and exit.
  --version             Display program version information and exit.
> cse inspect ../cse-core/test/data/fmi1/identity.fmu
name:         no.viproma.demo.identity
uuid:         ae713a03-634c-5da4-802e-9ea653e11f42
description:  Has one input and one output of each type, and outputs are always set equal to inputs
author:       Lars Tandle Kyllingstad
version:      0.3
variables:
  - name:         realIn
    reference:    0
    type:         real
    causality:    input
    variability:  discrete
    start value:  0
  - name:         integerIn
    reference:    0
    type:         integer
    causality:    input
    variability:  discrete
    start value:  0
  - name:         booleanIn
    reference:    0
    type:         boolean
    causality:    input
    variability:  discrete
    start value:  0
  - name:         stringIn
    reference:    0
    type:         string
    causality:    input
    variability:  discrete
    start value:
  - name:         realOut
    reference:    0
    type:         real
    causality:    output
    variability:  discrete
  - name:         integerOut
    reference:    0
    type:         integer
    causality:    output
    variability:  discrete
  - name:         booleanOut
    reference:    0
    type:         boolean
    causality:    output
    variability:  discrete
  - name:         stringOut
    reference:    0
    type:         string
    causality:    output
    variability:  discrete

cse inspect file:///home/larky/development/osp/cse-core/test/data/fmi1/identity.fmu is equivalent and produces the exact same output. It should work with all our supported URI schemes, though I haven't tested them all.

> cse inspect ../cse-core/test/data/fmi1/identity.fmu --no-vars
name:         no.viproma.demo.identity
uuid:         ae713a03-634c-5da4-802e-9ea653e11f42
description:  Has one input and one output of each type, and outputs are always set equal to inputs
author:       Lars Tandle Kyllingstad
version:      0.3
ljamt commented 5 years ago

Feels a bit weird that cse run c:\dev\cse\cse-demos\dp-ship is valid syntax, but cse inspect c:\dev\cse\cse-demos\dp-ship\DPController.fmu is not valid and results in Error: No resolvers available to handle URI: c:\dev\cse\cse-demos\dp-ship\DPController.fmu

if we don't allow c:\dev\cse\.... we should provide examples on proper uri in the help like file:///c:/dev/cse...

kyllingstad commented 5 years ago

@ljamt:

Feels a bit weird that cse run c:\dev\cse\cse-demos\dp-ship is valid syntax, but cse inspect c:\dev\cse\cse-demos\dp-ship\DPController.fmu is not valid and results in Error: No resolvers available to handle URI: c:\dev\cse\cse-demos\dp-ship\DPController.fmu

I agree. A solution might be to make "X:\...", where X is any letter, a special case that is always treated as a path on Windows. There might exist corner cases where X is in fact a URI scheme, but we can deal with those if and when they arise. Agree?

ljamt commented 5 years ago

I agree. A solution might be to make "X:...", where X is any letter, a special case that is always treated as a path on Windows. There might exist corner cases where X is in fact a URI scheme, but we can deal with those if and when they arise. Agree?

Sounds good to me.

kyllingstad commented 5 years ago

Done.

hplatou commented 5 years ago

Looks good. One question: Should we consider adding parameter for not printing variables? That could be very verbose for some models.

kyllingstad commented 5 years ago

@hplatou:

Should we consider adding parameter for not printing variables?

Great idea! Coming right up.

kyllingstad commented 5 years ago

I've added a --no-vars option now. Updated the PR description with new examples too.