Skip to content

Commit

Permalink
Package kubectl
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpdp7 committed Mar 6, 2024
1 parent 68099b6 commit 15e1822
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions repo/kubectl.ubpkg.sky
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
stable_version = download_asset("https://cdn.dl.k8s.io/release/stable.txt", 16).as_string()

os_str = {
"linux": "linux",
"macos": "darwin",
}[os]

arch_str = {
"x86_64": "amd64",
"aarch64": "arm64",
}[arch]

install_binary(download_asset("https://dl.k8s.io/release/{stable_version}/bin/{os_str}/{arch_str}/kubectl".format(stable_version=stable_version, os_str=os_str, arch_str=arch_str), 128*1024*1024), "kubectl")
19 changes: 17 additions & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::needless_lifetimes, clippy::unnecessary_wraps)] // starlark weirdness

use std::io::Read;

use allocative::Allocative;
use starlark::environment::GlobalsBuilder;
use starlark::environment::{GlobalsBuilder, Methods, MethodsBuilder, MethodsStatic};
use starlark::starlark_simple_value;
use starlark::values::{
starlark_value, NoSerialize, ProvidesStaticType, StarlarkValue, Value, ValueLike,
Expand All @@ -19,8 +21,21 @@ impl std::fmt::Display for FileContents {
}
}

#[starlark_module]
fn file_contents_methods(builder: &mut MethodsBuilder) {
fn as_string(#[starlark(this)] receiver: Value) -> anyhow::Result<String> {
let file_contents = receiver.downcast_ref::<FileContents>().unwrap();
Ok(String::from_utf8(file_contents.contents.clone())?)
}
}

#[starlark_value(type = "file_contents")]
impl<'v> StarlarkValue<'v> for FileContents {}
impl<'v> StarlarkValue<'v> for FileContents {
fn get_methods() -> Option<&'static Methods> {
static RES: MethodsStatic = MethodsStatic::new();
RES.methods(file_contents_methods)
}
}

#[starlark_module]
pub fn base(builder: &mut GlobalsBuilder) {
Expand Down

0 comments on commit 15e1822

Please sign in to comment.