Re: ENVIROMENT UPDATE

59 views
Skip to first unread message

Serj Kalichev

unread,
Jul 23, 2024, 2:29:09 PM7/23/24
to kl...@googlegroups.com
Hello
Which klish version do you use?


23.07.2024 05:58, wangping пишет:
Hello,

I just found this amazing command-line project. Compared to several other projects I've seen before, this one is really much better. However, there are still a few issues that are bothering me, and I would like to confirm with you.

```
export TEST_MODULE_A_ENABLED="false"
export TEST_MODULE_B_ENABLED="false"
...

/path/to/my/clish "$@" -o -l

...
```
This is my clish_start script, 
question is "can i change TEST_MODULE_A_ENABLED during clish running?"

the original need is that commandA has a lot of params, but i only want to expose part of them to user until user explicitly enables module A through a command.

Welcome any complete solutions or ideas.

  1. thanks to all of you. great job again.

--
You received this message because you are subscribed to the Google Groups "klish" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/klish/b41a4f8f-f545-4b24-a2c6-af4b82622a6cn%40googlegroups.com.


Message has been deleted
Message has been deleted

wangping

unread,
Jul 24, 2024, 4:26:47 AM7/24/24
to klish
Thank you very much for your reply. 

I am using the 2.2.x version with my own changes. 
I need further clarification and details on my requirements. I am not sure whether the latest version or any other existing version can meet these requirements. 

KLISH does not natively support the test tag of COMMAND. I used some simple methods to implement this feature first, at least when exposed to users. 

Then I encountered a problem. I developed the H feature for these development boards. This feature supports multiple profiles. Different profiles should expose different commands for users. 

The first way I thought of was to use the test attribute in COMMAND, but I found that these environment variables seem to be fixed after the process is started. 

Is there any way to use some variables in the test statement in the condition expression, or execute a script? 

I noticed that test actually only implements simple string comparison and reading of file information (modification time, permissions, size, etc.). 

What should I do if I want to use some variables or read some values ​​stored in the file through a script?

wangping

unread,
Jul 24, 2024, 4:26:47 AM7/24/24
to klish
Thank you very much for your reply. 

I am using the 2.2.x version with my own changes. I need further clarification and details on my requirements. I am not sure whether the latest version or any other existing version can meet these requirements. 

KLISH does not natively support the test tag of COMMAND. I used some simple methods to implement this feature first, at least when facing users. Then I encountered a problem. 

I developed the H feature for these development boards. This feature supports multiple profiles. Different profiles have different commands for users. 

The first way I thought of was to use the test attribute in COMMAND, but I found that these environment variables seem to be fixed after the process is started.

 Is there any way to use some variables in the test statement in the condition expression, or execute a script? 

I noticed that test actually only implements simple string comparison and reading of file information (modification time, permissions, size, etc.).

 What should I do if I want to use some variables or read some values ​​stored in the file through a script?

On Wednesday, July 24, 2024 at 2:29:09 AM UTC+8 Serj Kalichev wrote:

Serj Kalichev

unread,
Jul 24, 2024, 4:51:36 AM7/24/24
to kl...@googlegroups.com
Actually COMMAND doesn't have 'test' attribute. The PARAM does.

The COMMAND has 'access' attribute. We used it to control user access rights. By default 'access' field is based on unix groups but klish allows to implement your own hook to handle content of access field. The klish checks 'access' on start. If user has no rights for command then it will not see it at all.

Additionally klish has dynamic VARs. VAR can execute any action.

Generally you can't set environment variables and preserve them because klish is forked to execute any script. Maybe custom plugin and custom symbol can help. C-code can be executed without forking


24.07.2024 06:37, wangping пишет:

Mark Murawski

unread,
Jul 24, 2024, 10:01:11 AM7/24/24
to kl...@googlegroups.com
Hi,

This is what I use for run-time variables.  I'm using a very very old version of klish and this works well.

I do an action that executes a bash script to toggle a value in a tmp file
Every cli user gets their own 'session file' on startup.

- Use a script to start clish (don't start it directly)
- In the script, use mktemp or something similar to make a tmp file for the user, set environment variable in startup script KLISH_STATE
- And now you can make flags, like ${KLISH_STATE}-debug  ${KLISH_STATE}-module-b-enable   ${KLISH_STATE}-module-b-enable


You can do something like this, to always show the value in the prompt
This XML works on an older version and may need to be converted.


<STARTUP view="enable-view">
  <VAR name="SYSTEM_NAME" help="" dynamic="true">
    <ACTION>
      echo -n `hostname`

      if [ "${DEBUG}" -eq 1 ]; then echo -n ' (DEBUG) '; fi
    </ACTION>
  </VAR>
....cut....

<VAR name="DEBUG" dynamic="true"><ACTION>if [ -e "${KLISH_STATE}-debug" ]; then cat "${KLISH_STATE}-debug"; else echo -n 0; fi</ACTION></VAR>



<VIEW name="enable-view"
        prompt="${SYSTEM_NAME}# ">

        <COMMAND name="debug"
                help="Turn on backend debug"
        >
          <ACTION>
            DEBUG=${DEBUG}

            if [ 0${DEBUG} -eq 0 ]; then
              DEBUG=1
              echo "DEBUG Enabled"
            else
              DEBUG=0
              echo "DEBUG Disabled"
            fi

            echo -n $DEBUG > "${KLISH_STATE}-debug"
          </ACTION>
        </COMMAND>


And then you can toggle the value by typing the debug command.  Each time you run debug command, it will switch the value

You can then use ${DEBUG} anywhere in <ACTION> elements and it will be 1 or 0

wangping

unread,
Jul 25, 2024, 10:36:04 AM7/25/24
to klish
Thanks for your tips, i didn't try VAR before, i will try to use this.

for test in COMMAND, I will raise a PR later if i'm not busy on work.

this is a really a great project, which helped me a lot. 

Thank you.

wangping

unread,
Jul 25, 2024, 10:38:57 AM7/25/24
to klish
thanks for your kind tips. 

this is another way to implement the need. And will do this if i failed in my new idea.

have a good day!

Reply all
Reply to author
Forward
0 new messages