8000 Add action summary information. (#254) by shawn111 · Pull Request #401 · comtrya/comtrya · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add action summary information. (#254) #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2024
Merged

Conversation

shawn111
Copy link
Contributor

I'm submitting a

  • bug fix
  • [ *] feature
  • documentation addition

What is the current behaviour?

Even run -vv (tracing mode), didn't provide action key information.
For example CopyFile, can't figure out about source and destination.

current output look like,

TRACE load_config{args=GlobalArgs { manifest_directory: None, no_color: false, verbose: 2, command: Apply(Apply { manifests: [], dry_run: false, label: None }) }}:load_config: No Comtrya.yaml found in current working directory
TRACE load_config{args=GlobalArgs { manifest_directory: None, no_color: false, verbose: 2, command: Apply(Apply { manifests: [], dry_run: false, label: None }) }}:load_config: No Comtrya.yaml found in users config directory
TRACE build_contexts: context="user" key="id" value="1000"
...
TRACE build_contexts: context="env" key="MANAGERPID" value="116167"
TRACE execute: manifests=""
...
TRACE execute: Add dynamic constant 'user' -> #{"config_dir": "/home/shawn/.config", "data_dir": "/home/shawn/.local/share", "data_local_dir": "/home/shawn/.local/share", "document_dir": "/home/shawn/Documents", "home_dir": "/home/shawn", "id": "1000", "name": "Shawn Wang", "username": "shawn"}
TRACE execute: Add dynamic constant 'variables' -> #{}
...
TRACE execute:{manifest="sops"}:{action=file.copy}: Add dynamic constant 'user' -> #{"config_dir": "/home/shawn/.config", "data_dir": "/home/shawn/.local/share", "data_local_dir": "/home/shawn/.local/share", "document_dir": "/home/shawn/Documents", "home_dir": "/home/shawn", "id": "1000", "name": "Shawn Wang", "username": "shawn"}
TRACE execute:{manifest="sops"}:{action=file.copy}: Add dynamic constant 'variables' -> #{}
 INFO execute:{manifest="sops"}: Completed

What is the expected behavior?

╰─❯ /home/shawn/comtrya/target/debug/comtrya   apply
 INFO execute:{manifest="sops"}:{action=file.copy}: copy file from x1234 to y
 INFO execute:{manifest="sops"}: Completed
╰─❯ /home/shawn/comtrya/target/debug/comtrya   apply --dry-run
 INFO execute:{manifest="sops"}:{action=file.copy}: copy file from x1234 to y

Please tell us about your environment:

Version (comtrya --version): comtrya 0.8.8
Operating system: linux

@shawn111
Copy link
Contributor Author

I add a default trait method, but if we think this is a good direction.
Maybe remove default trait method to force all action make a clear summarize would be better.

pub trait Action {
    fn summarize(&self) -> String {
 +       warn!(
 +           "not found action summarize: {}",
 +           std::any::type_name_of_val(self)
 +       );
 +       format!("{:?}", std::any::type_name_of_val(self))
    }
    fn plan(&self, manifest: &Manifest, context: &Contexts) -> anyhow::Result<Vec<Step>>;
}

@rawkode
Copy link
Member
rawkode commented Feb 28, 2024

Should this be called after a plan has co firmed we want to run? Rather than printing summaries of plans we don't need to action?

@shawn111
Copy link
Contributor Author
shawn111 commented Feb 28, 2024

I'm not sure where is the good place to call it.
Just thought the original information is too limit.

BTW, my idea is even in dry-run, it shows what actions would be called.

@shawn111
Copy link
Contributor Author

@rawkode Thanks, I moved it to line 254 ish. I can't find line 324 ish. Is this what you mean?

@rawkode
Copy link
Member
rawkode commented Feb 28, 2024

Oops. I meant 234's ish, but where you have put it is fine.

Happy to merge

@shawn111
Copy link
Contributor Author

Avoid to use std::any::type_name_of_val.

Here is the new output with default summarize.

home/shawn/comtrya/target/debug/comtrya -v  apply
 INFO execute:{manifest="sops"}:{action=file.copy}: copy file from x1234 to /tmp/y
 WARN execute:{manifest="sops"}:{action=file.remove}: need to define action summarize
 INFO execute:{manifest="sops"}:{action=file.remove}: not found action summarize
 INFO execute:{manifest="sops"}: Completed

@rawkode rawkode merged commit 0a5cdc0 into comtrya:main Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0