-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out shared code from start and stop
- Loading branch information
1 parent
dbda60a
commit d31b8be
Showing
4 changed files
with
49 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use core::fmt; | ||
|
||
use bollard::{ClientVersion, Docker}; | ||
use clap::ValueEnum; | ||
|
||
// DEFAULT_TIMEOUT and API_DEFAULT_VERSION are from the bollard crate | ||
const DEFAULT_TIMEOUT: u64 = 120; | ||
const API_DEFAULT_VERSION: &ClientVersion = &ClientVersion { | ||
major_version: 1, | ||
minor_version: 40, | ||
}; | ||
|
||
#[derive(ValueEnum, Debug, Clone, PartialEq)] | ||
pub enum Network { | ||
Local, | ||
Testnet, | ||
Futurenet, | ||
Pubnet, | ||
} | ||
|
||
impl fmt::Display for Network { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let variant_str = match self { | ||
Network::Local => "local", | ||
Network::Testnet => "testnet", | ||
Network::Futurenet => "futurenet", | ||
Network::Pubnet => "pubnet", | ||
}; | ||
|
||
write!(f, "{}", variant_str) | ||
} | ||
} | ||
|
||
pub fn connect_to_docker(docker_socket_path: Option<String>) -> Docker { | ||
if docker_socket_path.is_some() { | ||
let socket = docker_socket_path.as_ref().unwrap(); | ||
Docker::connect_with_socket(socket, DEFAULT_TIMEOUT, API_DEFAULT_VERSION).unwrap() | ||
} else { | ||
Docker::connect_with_socket_defaults().unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters