Skip to content
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

Add --stdout/-o to our CLI helper library #4544

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/rerun/src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ enum RerunBehavior {

Save(PathBuf),

Stdout,

#[cfg(feature = "web_viewer")]
Serve,

Expand Down Expand Up @@ -47,6 +49,10 @@ pub struct RerunArgs {
#[clap(long)]
save: Option<PathBuf>,

/// Log data to standard output, to be piped into a Rerun Viewer.
#[clap(long, short = 'o')]
stdout: bool,

/// Connects and sends the logged data to a remote Rerun viewer.
///
/// Optionally takes an `ip:port`.
Expand Down Expand Up @@ -89,6 +95,11 @@ impl RerunArgs {
#[track_caller] // track_caller so that we can see if we are being called from an official example.
pub fn init(&self, application_id: &str) -> anyhow::Result<(RecordingStream, ServeGuard)> {
match self.to_behavior()? {
RerunBehavior::Stdout => Ok((
RecordingStreamBuilder::new(application_id).stdout()?,
Default::default(),
)),

RerunBehavior::Connect(addr) => Ok((
RecordingStreamBuilder::new(application_id)
.connect_opts(addr, crate::default_flush_timeout())?,
Expand Down Expand Up @@ -144,6 +155,10 @@ impl RerunArgs {

#[allow(clippy::unnecessary_wraps)] // False positive on some feature flags
fn to_behavior(&self) -> anyhow::Result<RerunBehavior> {
if self.stdout {
return Ok(RerunBehavior::Stdout);
}

if let Some(path) = self.save.as_ref() {
return Ok(RerunBehavior::Save(path.clone()));
}
Expand Down
11 changes: 10 additions & 1 deletion rerun_py/rerun_sdk/rerun/script_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def script_add_args(parser: ArgumentParser) -> None:
)
parser.add_argument("--addr", type=str, default=None, help="Connect to this ip:port")
parser.add_argument("--save", type=str, default=None, help="Save data to a .rrd file at this path")
parser.add_argument(
"-o",
"--stdout",
dest="stdout",
action="store_true",
help="Log data to standard output, to be piped into a Rerun Viewer",
)


def script_setup(
Expand All @@ -77,7 +84,9 @@ def script_setup(
rec: RecordingStream = rr.get_global_data_recording() # type: ignore[assignment]

# NOTE: mypy thinks these methods don't exist because they're monkey-patched.
if args.serve:
if args.stdout:
rec.stdout() # type: ignore[attr-defined]
elif args.serve:
rec.serve() # type: ignore[attr-defined]
elif args.connect:
# Send logging data to separate `rerun` process.
Expand Down
Loading