Overriding juju command

Hi,

I was wondering if it would be possible to override, actually extend, juju commands .
What I am looking for is the option to run a custom hook before e.g. juju config is executed.
I tried using the juju plugin framework for this, but that does not seem work.

Placing a file called juju-config in my path was as content a simple echo line an calling /snap/bin/juju config directly does not work, as this file is not called.

Not sure that such a thing (custom hooks for juju calls) is actually possible, but it would be a great feature.

So you’re looking to run a custom hook from within a charm? The plugin framework is used mainly for the juju CLI and not directly for a charm, it allows people to extend juju in new and interesting ways.

What are you looking to try and do, there might be another approach?

I am looking into a way if it is possible to replicate etckeeper like functionality to juju. So that before config changes are made the current ‘state’ can be recorded in a version control system, with ideally the command run as the commit message.

Looking to see if this is possible in some way. So I am definitely not talking about charm hooks.

@woutervb ok, this is more my territory, so the plugin framework will work in the following way:

  1. Firstly it will try to match a command to an existing juju command.
  2. Failure to find a juju command will then see if there is a “thing” that matches that on your $PATH.

The intention is to prevent you from overloading an existing juju command to prevent you from confusing users with new plugins. So from a basic juju stand point, what you’re trying to do isn’t possible, but you have two options to try and accomplish what you’re attempting to do:

  1. Create a juju config2 (name it some other thing) - which performs a backup of the world and then calls juju config. I did something similar here https://github.com/SimonRichardson/juju-stash
  2. Use bash/shell to do things for you (create an function that intercepts the call), I wouldn’t advise this as it makes things more magical, but it is available to you.