Skip to content

override / silence output on change of settable #1420

Closed

Description

@gjvc

when changing a settable, i would like to do my own logging / printing of the fact, and override / silence the built-in output.

For example:

> set package_path devel/mold/2.36
2025-05-22T23:45:05.615 I           t/b/s/shell.py:99   package_path='lang/python/3.10' -> 'devel/mold/2.36'
package_path - was: 'lang/python/3.10'
now: 'devel/mold/2.36'

The logging line is mine, and I would like to silence the two lines below it.

cmd2==2.5.11, python 3.13

Activity

  1. tleonhardt commented on May 23, 2025

    @tleonhardt
    Member

    @gjvc This is an interesting and reasonable suggestion. I can see several potential ways to go about it, including at least all of the following:

    1. Add -q/--quiet flag to the set command that suppresses default output from cmd2. This is easily done. It would require users to add the -q flag each time.
    2. Add an optional boolean parameter to the cmd2.Cmd.__init__() method called something like silence_set which has a global effect of silencing the default cmd2 output from the set command. This is also relatively easy and has the benefit of not requiring users to enter anything each time.
    3. You can override the do_set method of cmd2.Cmd in your application and modify accordingly. Also easy, but requires work on your end, not on the cmd2 end.

    Which do you think would best meet your needs and would provide the best overall user experience?

  2. added this to the 2.6.2 milestone on Jun 12, 2025
  3. self-assigned this
    on Jun 12, 2025
  4. tleonhardt commented on Jun 13, 2025

    @tleonhardt
    Member

    @gjvc Would simply redirecting the output of that command to /dev/null be a reasonable option for you?

    set package_path devel/mold/2.36 > /dev/null
    2025-05-22T23:45:05.615 I           t/b/s/shell.py:99   package_path='lang/python/3.10' -> 'devel/mold/2.36'

    The easiest option I see is for you to either just redirect to /dev/null or to override the do_set method in your class which inherits from cmd2.Cmd. If you want to override it, just make a copy of our code and delete the line with the poutput call outputting that output. Alternatively, you can change the poutput to a pfeedback and change the quiet setting in your app to default to True.

    I don't like the option of adding a -q flag to the set command, it just doesn't feel right for that command. I also don't like the idea of adding another optional parameter to the __init__() method for cmd2.Cmd for this niche case.

    If we had it to do over again, we would perhaps choose to use pfeedback instead of poutput to output that info as it isn't really essential, but doing it at this point would be a breaking change which would pretty much be guaranteed to break someone else's application.

  5. locked and limited conversation to collaborators on Jun 13, 2025
  6. converted this issue into a discussion #1448 on Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions