-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1314 from BohuTANG/cli-package-switch-938
CLI-938: add datafuse-cli package switch command
- Loading branch information
Showing
8 changed files
with
115 additions
and
8 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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
pub mod fetch; | ||
pub mod list; | ||
pub mod package; | ||
pub mod switch; |
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,53 @@ | ||
// Copyright 2020-2021 The Datafuse Authors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0. | ||
|
||
use std::fs; | ||
|
||
use crate::cmds::Config; | ||
use crate::cmds::ListCommand; | ||
use crate::cmds::Status; | ||
use crate::cmds::Writer; | ||
use crate::error::Result; | ||
|
||
#[derive(Clone)] | ||
pub struct SwitchCommand { | ||
conf: Config, | ||
} | ||
|
||
impl SwitchCommand { | ||
pub fn create(conf: Config) -> Self { | ||
SwitchCommand { conf } | ||
} | ||
|
||
pub fn exec(&self, writer: &mut Writer, args: String) -> Result<()> { | ||
let bin_dir = format!("{}/bin", self.conf.datafuse_dir.clone()); | ||
let paths = fs::read_dir(bin_dir)?; | ||
|
||
let mut exists = false; | ||
for path in paths { | ||
let path = path.unwrap().path(); | ||
let version = path.file_name().unwrap().to_string_lossy().into_owned(); | ||
if version == args { | ||
exists = true; | ||
break; | ||
} | ||
} | ||
|
||
if !exists { | ||
writer.write_err(format!("Can't found version: {}, package list:", args).as_str()); | ||
let list = ListCommand::create(self.conf.clone()); | ||
list.exec(writer, args)?; | ||
return Ok(()); | ||
} | ||
|
||
// Write to status. | ||
let mut status = Status::read(self.conf.clone())?; | ||
status.version = args.clone(); | ||
status.write()?; | ||
|
||
writer.write_ok(format!("Package switch to {}", args).as_str()); | ||
|
||
Ok(()) | ||
} | ||
} |
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