Move some things around

pull/189/head
Chip Senkbeil 1 year ago
parent 93657af270
commit ca683a828f
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `set_permissions` method available `DistantApi` and implemented by local
server (ssh unavailable due to https://github.com/wez/wezterm/issues/3784)
- Implementation of `DistantChannelExt::set_permissions`
- `distant version` to display information about connected server
### Changed
@ -26,6 +27,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
array or a string and no longer an object with a `type` and `value` field
- Unset options and values are not now returned in `JSON` serialization versus
the explicit `null` value provided
- `Capabilities` message type has been changed to `Version` with new struct to
report the version information that includes a server version string,
protocol version tuple, and capabilities
### Removed
- `distant capabilities` has been removed in favor of `distant version`
## [0.20.0-alpha.6]

@ -49,106 +49,6 @@ async fn read_cache(path: &Path) -> Cache {
async fn async_run(cmd: ClientSubcommand) -> CliResult {
match cmd {
ClientSubcommand::Version {
cache,
connection,
format,
network,
} => {
debug!("Connecting to manager");
let mut client = connect_to_manager(format, network).await?;
let mut cache = read_cache(&cache).await;
let connection_id =
use_or_lookup_connection_id(&mut cache, connection, &mut client).await?;
debug!("Opening raw channel to connection {}", connection_id);
let channel = client
.open_raw_channel(connection_id)
.await
.with_context(|| {
format!("Failed to open raw channel to connection {connection_id}")
})?;
debug!("Retrieving version information");
let version = channel
.into_client()
.into_channel()
.version()
.await
.with_context(|| {
format!("Failed to retrieve version using connection {connection_id}")
})?;
match format {
Format::Shell => {
println!("Server version: {}", version.server_version);
let (major, minor, patch) = version.protocol_version;
println!("Protocol version: {major}.{minor}.{patch}");
// Build a complete set of capabilities to show which ones we support
let client_capabilities = Capabilities::all();
let server_capabilities = version.capabilities;
let mut capabilities: Vec<String> = client_capabilities
.union(server_capabilities.as_ref())
.map(|cap| {
let kind = &cap.kind;
if client_capabilities.contains(kind)
&& server_capabilities.contains(kind)
{
format!("+{kind}")
} else {
format!("-{kind}")
}
})
.collect();
capabilities.sort_unstable();
// Figure out the text length of the longest capability
let max_len = capabilities.iter().map(|x| x.len()).max().unwrap_or(0);
if max_len > 0 {
const MAX_COLS: usize = 4;
// Determine how wide we have available to determine how many columns
// to use; if we don't have a terminal width, default to something
//
// Maximum columns we want to support is 4
let cols = match terminal_size::terminal_size() {
// If we have a tty, see how many we can fit including space char
//
// Ensure that we at least return 1 as cols
Some((width, _)) => std::cmp::max(width.0 as usize / (max_len + 1), 1),
// If we have no tty, default to 4 columns
None => MAX_COLS,
};
println!("Capabilities supported (+) or not (-):");
for chunk in capabilities.chunks(std::cmp::min(cols, MAX_COLS)) {
let cnt = chunk.len();
match cnt {
1 => println!("{:max_len$}", chunk[0]),
2 => println!("{:max_len$} {:max_len$}", chunk[0], chunk[1]),
3 => println!(
"{:max_len$} {:max_len$} {:max_len$}",
chunk[0], chunk[1], chunk[2]
),
4 => println!(
"{:max_len$} {:max_len$} {:max_len$} {:max_len$}",
chunk[0], chunk[1], chunk[2], chunk[3]
),
_ => unreachable!("Chunk of size {cnt} is not 1 > i <= {MAX_COLS}"),
}
}
}
}
Format::Json => {
println!("{}", serde_json::to_string(&version).unwrap())
}
}
}
ClientSubcommand::Connect {
cache,
destination,
@ -605,6 +505,106 @@ async fn async_run(cmd: ClientSubcommand) -> CliResult {
.context("Failed to write system information to stdout")?;
out.flush().context("Failed to flush stdout")?;
}
ClientSubcommand::Version {
cache,
connection,
format,
network,
} => {
debug!("Connecting to manager");
let mut client = connect_to_manager(format, network).await?;
let mut cache = read_cache(&cache).await;
let connection_id =
use_or_lookup_connection_id(&mut cache, connection, &mut client).await?;
debug!("Opening raw channel to connection {}", connection_id);
let channel = client
.open_raw_channel(connection_id)
.await
.with_context(|| {
format!("Failed to open raw channel to connection {connection_id}")
})?;
debug!("Retrieving version information");
let version = channel
.into_client()
.into_channel()
.version()
.await
.with_context(|| {
format!("Failed to retrieve version using connection {connection_id}")
})?;
match format {
Format::Shell => {
println!("Server version: {}", version.server_version);
let (major, minor, patch) = version.protocol_version;
println!("Protocol version: {major}.{minor}.{patch}");
// Build a complete set of capabilities to show which ones we support
let client_capabilities = Capabilities::all();
let server_capabilities = version.capabilities;
let mut capabilities: Vec<String> = client_capabilities
.union(server_capabilities.as_ref())
.map(|cap| {
let kind = &cap.kind;
if client_capabilities.contains(kind)
&& server_capabilities.contains(kind)
{
format!("+{kind}")
} else {
format!("-{kind}")
}
})
.collect();
capabilities.sort_unstable();
// Figure out the text length of the longest capability
let max_len = capabilities.iter().map(|x| x.len()).max().unwrap_or(0);
if max_len > 0 {
const MAX_COLS: usize = 4;
// Determine how wide we have available to determine how many columns
// to use; if we don't have a terminal width, default to something
//
// Maximum columns we want to support is 4
let cols = match terminal_size::terminal_size() {
// If we have a tty, see how many we can fit including space char
//
// Ensure that we at least return 1 as cols
Some((width, _)) => std::cmp::max(width.0 as usize / (max_len + 1), 1),
// If we have no tty, default to 4 columns
None => MAX_COLS,
};
println!("Capabilities supported (+) or not (-):");
for chunk in capabilities.chunks(std::cmp::min(cols, MAX_COLS)) {
let cnt = chunk.len();
match cnt {
1 => println!("{:max_len$}", chunk[0]),
2 => println!("{:max_len$} {:max_len$}", chunk[0], chunk[1]),
3 => println!(
"{:max_len$} {:max_len$} {:max_len$}",
chunk[0], chunk[1], chunk[2]
),
4 => println!(
"{:max_len$} {:max_len$} {:max_len$} {:max_len$}",
chunk[0], chunk[1], chunk[2], chunk[3]
),
_ => unreachable!("Chunk of size {cnt} is not 1 > i <= {MAX_COLS}"),
}
}
}
}
Format::Json => {
println!("{}", serde_json::to_string(&version).unwrap())
}
}
}
ClientSubcommand::FileSystem(ClientFileSystemSubcommand::Copy {
cache,
connection,

@ -103,9 +103,6 @@ impl Options {
network.merge(config.client.network);
*timeout = timeout.take().or(config.client.api.timeout);
}
ClientSubcommand::Version { network, .. } => {
network.merge(config.client.network);
}
ClientSubcommand::Connect {
network, options, ..
} => {
@ -153,6 +150,9 @@ impl Options {
ClientSubcommand::SystemInfo { network, .. } => {
network.merge(config.client.network);
}
ClientSubcommand::Version { network, .. } => {
network.merge(config.client.network);
}
}
}
DistantSubcommand::Generate(_) => {
@ -263,28 +263,6 @@ pub enum ClientSubcommand {
network: NetworkSettings,
},
/// Retrieves capabilities of the remote server
Version {
/// Location to store cached data
#[clap(
long,
value_hint = ValueHint::FilePath,
value_parser,
default_value = CACHE_FILE_PATH_STR.as_str()
)]
cache: PathBuf,
/// Specify a connection being managed
#[clap(long)]
connection: Option<ConnectionId>,
#[clap(flatten)]
network: NetworkSettings,
#[clap(short, long, default_value_t, value_enum)]
format: Format,
},
/// Requests that active manager connects to the server at the specified destination
Connect {
/// Location to store cached data
@ -458,12 +436,33 @@ pub enum ClientSubcommand {
#[clap(flatten)]
network: NetworkSettings,
},
/// Retrieves version information of the remote server
Version {
/// Location to store cached data
#[clap(
long,
value_hint = ValueHint::FilePath,
value_parser,
default_value = CACHE_FILE_PATH_STR.as_str()
)]
cache: PathBuf,
/// Specify a connection being managed
#[clap(long)]
connection: Option<ConnectionId>,
#[clap(flatten)]
network: NetworkSettings,
#[clap(short, long, default_value_t, value_enum)]
format: Format,
},
}
impl ClientSubcommand {
pub fn cache_path(&self) -> &Path {
match self {
Self::Version { cache, .. } => cache.as_path(),
Self::Connect { cache, .. } => cache.as_path(),
Self::FileSystem(fs) => fs.cache_path(),
Self::Launch { cache, .. } => cache.as_path(),
@ -471,12 +470,12 @@ impl ClientSubcommand {
Self::Shell { cache, .. } => cache.as_path(),
Self::Spawn { cache, .. } => cache.as_path(),
Self::SystemInfo { cache, .. } => cache.as_path(),
Self::Version { cache, .. } => cache.as_path(),
}
}
pub fn network_settings(&self) -> &NetworkSettings {
match self {
Self::Version { network, .. } => network,
Self::Connect { network, .. } => network,
Self::FileSystem(fs) => fs.network_settings(),
Self::Launch { network, .. } => network,
@ -484,6 +483,7 @@ impl ClientSubcommand {
Self::Shell { network, .. } => network,
Self::Spawn { network, .. } => network,
Self::SystemInfo { network, .. } => network,
Self::Version { network, .. } => network,
}
}
}

Loading…
Cancel
Save